-
Notifications
You must be signed in to change notification settings - Fork 33
Home
XboxCtrlrInput
is a wrapper written in C# for Unity3D that handles Xbox 360 controller input. It's used in the same way as Unity's Input
class. The goals of XboxCtrlrInput
are:
- To be able to make simple calls to Xbox controller input that works on Mac, Windows, and Linux (Ubuntu),
- And to be able to handle multiple Xbox controllers that works as you expect.
XboxCtrlrInput.cs
itself is not a Unity script and thus does not need to be attached to any GameObject, since it contains no MonoBehavior
s. Unity's Input
class works in a similar way. XboxCtrlrInput
should work on older versions of Unity that support joystick input.
Note for Mac users: Be sure to install the latest version of the Tattie Bogle drivers.
Note for Linux users: All of my Linux testing was done on Ubuntu 13.04 64-bit. To test 32-bit Unity builds on a 64-bit OS, I ran sudo apt-get install ia32-libs
in a terminal. I am using the default Xbox controller driver that came with Ubuntu, which is known as xpad. I could not get Unity builds to cooperate with xboxdrv. Your milage may vary.
-
Download the XboxCtrlrInput C# file (Right Click -> Save As...) and then put it into your Unity project under the
Assets/
folder. It can be anywhere in that folder. -
Next, take the a copy of Unity's Input Manager (either as a text asset or as a binary asset ) (Right Click -> Save As...). Place that copy into your project's
/ProjectSettings
folder. Then rename itInputManager.asset
, this will replace the original file that was there. -
For any C# script where you want to Xbox input, place
using XboxCtrlrInput;
at the top of the script underusing UnityEngine;
. -
The
XboxCtrlrInput
namespace includes the classXCI
, which you will use to get Xbox input, such as:
bool didPressA = XCI.GetButton(XboxButton.A);
- The code in
XboxCtrlrInput.cs
should work in Unity 4.x and above. - It might work in previous versions as long as they support joystick input.
- The example project requires Unity 4.2 or above (mostly due to the free text asset serialization).
- This class was mostly designed for desktop OS games in mind (Mac/Windows/Linux). This probably won't work for console or mobile development.
If you want to find out what currently works (such as button mappings), refer to the What Works page.
Please refer to the Issues page for the latest issues.
XboxButton |
Used to identify different Xbox buttons. |
---|---|
XboxDPad |
Used to refer to the four D-Pad directions. |
XboxAxis |
Used to identify all of the Xbox's analog inputs. |
There are none, as of yet anyway.
GetButton() |
Returns true if the specified button is held down. |
---|---|
GetButtonDown() |
Returns true at the frame the specified button starts to press down (not held down). |
GetButtonUp() |
Returns true at the frame the specified button is released. |
GetDPad() |
Returns true if the specified D-Pad direction is pressed down. |
GetAxis() |
Returns the analog number of the specified axis. |
GetAxisRaw() |
Returns the analog number of the specified axis without Unity's smoothing filter. |