After checking the forums I managed to setup an XBox controller for presentations, the only thing I don’t understand is the d-pad. How does it work? I wanted to use it as simple buttons and not axis. Is that possible? I see that the mac driver treat D-pad as buttons is that the case for PC too?
Here are the mappings:
Thanks.
EDIT: I think I have to make a script that takes the Axis -1 1 and transform them to boolean buttons, is the dpad the 7th and 6th axis?
Fun. So the examples above do not compile or they are unfortunately wrong. This is an old thread … but if you are wanting to treat DPad input as a non-repeating button (e.g. Input.GetButtonDown), here’s an approach that is simple and likely the fewest number of operations possible. Make sure to attach this script to a game object.
using UnityEngine;
public class DPadButtons : MonoBehaviour
{
public static bool IsLeft, IsRight, IsUp, IsDown;
private float _LastX, _LastY;
private void Update()
{
float x = Input.GetAxis("DPad X");
float y = Input.GetAxis("DPad Y");
IsLeft = false;
IsRight = false;
IsUp = false;
IsDown = false;
if (_LastX != x)
{
if (x == -1)
IsLeft = true;
else if (x == 1)
IsRight = true;
}
if (_LastY != y)
{
if (y == -1)
IsDown = true;
else if (y == 1)
IsUp = true;
}
_LastX = x;
_LastY = y;
}
}
Since I just found this page trying to do it myself, and nobody had an answer, I thought I’d post what I just came up with to achieve the result the OP was asking about (that is, using the DPad buttons as buttons rather than axes)
You need to do it yourself, unfortunately. Luckily, it’s not too hard. Something like this works fine:
using UnityEngine;
using System.Collections;
public class DPadButtons : MonoBehaviour {
public static bool up;
public static bool down;
public static bool left;
public static bool right;
float lastX;
float lastY;
public DPadButtons() {
up = down = left = right = false;
lastX = Input.GetAxis("DPadX");
lastY = Input.GetAxis("DpadY");
}
void Update() {
if(Input.GetAxis ("DPadX") == 1 && lastDpadX != 1) { right = true; } else { right = false; }
if(Input.GetAxis ("DPadX") == -1 && lastDpadX != -1) { left = true; } else { left = false; }
if(Input.GetAxis ("DPadY") == 1 && lastDpadY != 1) { up = true; } else { up = false; }
if(Input.GetAxis ("DPadY") == -1 && lastDpadY != -1) { down = true; } else { down = false; }
}
}
Then, in any script, you can do something like
if(DPadButtons.up) {
//some code to execute when the up button is pushed
}
I’m sure you could extend Unity’s Input class, but I don’t know how to do that, and this works find for me right now.
Converting joyStick Dpad( 6th & 7th Axis) to button.
i referred many communities for this but many of them where incomplete or non detailed.
so here is a simple version that everyone can get it. Thanks to @ CodeMasterMike.
Sorry i was late rpy…!