Mapping an Xbox One Controller in Unity (including alternate mappings for use on Android devices).
Button/Axis Name | Positive Button/Axis | Type |
---|---|---|
A Button | Joystick Button 0 | Key or Mouse Button |
B Button | Joystick Button 1 | Key or Mouse Button |
X Button | Joystick Button 2 | Key or Mouse Button |
Y Button | Joystick Button 3 | Key or Mouse Button |
Left Bumper | Joystick Button 4 | Key or Mouse Button |
Right Bumper | Joystick Button 5 | Key or Mouse Button |
View Button | Joystick Button 6 (PC), Joystick Button ??? (Android) | Key or Mouse Button |
Menu Button | Joystick Button 7 (PC), Joystick Button 10 (Android) | Key or Mouse Button |
L-Click Button | Joystick Button 8 | Key or Mouse Button |
R-Click Button | Joystick Button 9 | Key or Mouse Button |
Xbox Guide/Home Button | Joystick Button 12 | Key or Mouse Button |
Bluetooth Sync Button | ??? | Key or Mouse Button |
Left Analog Stick (Horizontal) | X Axis (Horizontal) | Joystick Axis |
Left Analog Stick (Vertical) | Y Axis (Vertical) | Joystick Axis |
Right Analog Stick (Horizontal) | 4th Axis (PC), 3rd Axis (Android) | Joystick Axis |
Right Analog Stick (Vertical) | 5th Axis (PC), 4th Axis (Android) | Joystick Axis |
D-Pad (Horizontal) | 6th Axis (PC), 5th Axis (Android) | Joystick Axis |
D-Pad (Vertical) | 7th Axis (PC), 6th Axis (Android) | Joystick Axis |
Left Trigger | 9th Axis (PC), 13th Axis (Android) | Joystick Axis |
Right Trigger | 10th Axis (PC), 12th Axis (Android) | Joystick Axis |
Button Settings:
Gravity: 1000
Dead: 0
Sensitivity: 1000
Axis Settings:
Gravity: 0
Dead: 0.19
Sensitivity: 1
NOTE: On a PC, the 3rd Axis is used for the mouse scroll wheel. However, because Android devices are not designed to be used with a mouse, the 3rd Axis on Android devices gets mapped to the horizontal axis on the right analog stick instead. This means that after the inital first two axes, most of the subsequent axis mappings are one number lower on Android than they are on PC. The only exceptions are the left and right triggers, which are mapped to the 13th and 12th axes, respectively.
I have not yet been able to figure out what the button number is for the View button on Android.
thank you rhianu! it's surprisingly difficult to find clear tables like this online. i think it's really strange that unity doesn't have presets for controller support built in yet.
i made this class for testing xbox controller inputs that i find useful. it just exposes some bools and floats to the inspector so you can make sure everything is working:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class XboxControllerTest : MonoBehaviour {
public bool aButton;
public bool bButton;
public bool xButton;
public bool yButton;
public bool leftBumper;
public bool rightBumper;
public bool viewButton;
public bool menuButton;
public bool lClickButton;
public bool rClickButton;
public bool xBoxGuideHomeButton;
public float leftAnalogStickHorizontal;
public float rightAnalogStickHorizontal;
public float leftAnalogStickVertical;
public float rightAnalogStickVertical;
public float dPadHorizontal;
public float dPadVertical;
public float leftTrigger;
public float rightTrigger;
void Update ()
{
aButton = Input.GetButton("A Button");
bButton = Input.GetButton("B Button");
xButton = Input.GetButton("X Button");
yButton = Input.GetButton("Y Button");
leftBumper = Input.GetButton("Left Bumper");
rightBumper = Input.GetButton("Right Bumper");
viewButton = Input.GetButton("View Button");
menuButton = Input.GetButton("Menu Button");
lClickButton = Input.GetButton("L-Click Button");
rClickButton = Input.GetButton("R-Click Button");
xBoxGuideHomeButton = Input.GetButton("Xbox Guide/Home Button");
leftAnalogStickHorizontal = Input.GetAxis("Left Analog Stick (Horizontal)");
rightAnalogStickHorizontal = Input.GetAxis("Right Analog Stick (Horizontal)");
leftAnalogStickVertical = Input.GetAxis("Left Analog Stick (Vertical)");
rightAnalogStickVertical = Input.GetAxis("Right Analog Stick (Vertical)");
dPadHorizontal = Input.GetAxis("D-Pad (Horizontal)");
dPadVertical = Input.GetAxis("D-Pad (Vertical)");
leftTrigger = Input.GetAxis("Left Trigger");
rightTrigger = Input.GetAxis("Right Trigger");
}
}
About Community
game developers
Online