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

GetDPadDown

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

<- Back to Coding References

Signature

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

Description

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

Precautions!

Be aware that GetDPadDown() 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 GetDPadDown() 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.GetDPadDown(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