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

GetDPadUp

Jibran Syed edited this page Mar 28, 2017 · 4 revisions

<- Back to Coding References

Signature

static bool GetDPadUp(XboxDPad padDirection);
static bool GetDPadUp(XboxDPad padDirection, XboxController controller);

Description

GetDPadUp() returns true the moment the specified D-Pad direction was released. The D-Pad had to be pressed down prior, and then released. It will return false any frame after the moment the direction was released. This is useful for interacting with menu selection with an Xbox controller, for example.

Precautions!

Be aware that GetDPadUp() currently doesn't work with wired controllers on Linux. See this merge request for more information.

Parameters

  • XboxDPad padDirection : An identifier for the specified D-Pad direction you want to test. Please refer to XboxDPad.

  • XboxController controller : An identifier for the specific controller on which to test the D-Pad. If this parameter isn't provided, all connected controllers will be tested for the specified D-Pad direction. 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 GetDPadUp() if you wanted a particular player to advance one tile right.

using UnityEngine;
using XboxCtrlrInput;

public class PlayerExample : MonoBehavior
{
    public XboxController playerNumber = XboxController.First;
    public float tileSize = 10.0f;    

    void Update()
    {
        if( XCI.GetDPadUp(XboxDPad.Right, playerNumber) )
        {
            // Walk right
            Vector3 newPosition = transform.position;
            float newPos = newPosition.x + tileSize;
            newPosition = new Vector3(newPos, transform.position.y, transform.position.z);
            transform.position = newPosition;
        }
    }
}
Clone this wiki locally