Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

GetButton

Jibran Syed edited this page Jan 30, 2016 · 15 revisions

<- Back to Coding References

Signature

static bool GetButton(XboxButton button);
static bool GetButton(XboxButton button, XboxController controller);

Description

GetButton() returns true if the specified XboxButton was pressed down at any frame. This would be useful for controls that would require the player to hold down a button, for example.

Parameters

  • XboxButton button : An identifier for the Xbox button you want to test. Please refer to XboxButton for all possible buttons.

  • XboxController controller : An identifier for the specific controller on which to test the button. If this parameter isn't provided, all connected controllers will be tested for the specified button. It is recommended to omit this parameter if you are making a single player game. Please refer to XboxController for all possible controllers.

Example

The example demonstrates the use of GetButton() if you wanted a particular player to continuously fire laser with the 'A' button.

using UnityEngine;
using XboxCtrlrInput;

public class PlayerExample : MonoBehavior
{
    public int XboxController playerNumber = XboxController.First;
    
    void Update()
    {
        if( XCI.GetButton(XboxButton.A, playerNumber) )
        {
            // Fire lasers here!
        }
    }
}

Button Map

ButtonMap

<- Back to Coding References

Clone this wiki locally