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

GetButtonDown

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

<- Back to Coding References

Signature

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

Description

GetButtonDown() returns true the single moment the specified XboxButton was pressed down. If the specified button was pressed down after that moment, it will return false. It will return true again if the button was released and then pressed down again. This is useful if you want the player to press down a button, but didn't intend for the button to be held down.

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 GetButtonDown() if you wanted a particular player to fire one missile from a single press of the 'B' button.

using UnityEngine;
using XboxCtrlrInput;

public class PlayerExample : MonoBehavior
{
    public XboxController playerNumber = XboxController.First;
    
    void Update()
    {
        if( XCI.GetButtonDown(XboxButton.B, playerNumber) )
        {
            // Fire the missile!
            // This will only run once until the button is released and pressed down again.
        }
    }
}

Button Map

ButtonMap

<- Back to Coding References

Clone this wiki locally