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

GetDPad

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

<- Back to Coding References

Signature

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

Description

GetDPad() returns true at any frame the specified D-Pad direction is pressed down. This would be useful for arcade-style movement, for example.

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 GetDPad() if you wanted a particular player to walk right.

using UnityEngine;
using XboxCtrlrInput;

public class PlayerExample : MonoBehavior
{
    public XboxController playerNumber = XboxController.First;
    public float walkingSpeed = 7.0f;    

    void Update()
    {
        if( XCI.GetDPad(XboxDPad.Right, playerNumber) )
        {
            // Walk right
            Vector3 newPosition = transform.position;
            float newPos = newPosition.x + (walkingSpeed * Time.deltaTime);
            newPosition = new Vector3(newPos, transform.position.y, transform.position.z);
            transform.position = newPosition;
        }
    }
}

D-Pad Map

DPadMap

<- Back to Coding References

Clone this wiki locally