-
Notifications
You must be signed in to change notification settings - Fork 33
GetButtonDown
static bool GetButtonDown(XboxButton button);
static bool GetButtonDown(XboxButton button, XboxController controller);
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.
-
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.
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.
}
}
}