Getting Raw Joystick Input via Script

I’m trying to deal with controllers in a programmatic way.
The InputManager is a massive hassle.

I want to work out what Unity calls each of the buttons I press, for a few reasons:

  • Binding input from unknown controller types to actions.
  • Debugging what Unity calls each button (e.g. controller type A has button X, which Unity thinks is Button7

For keyboard it seems i can do:

void OnGUI() {
	Event e = Event.current;
	if (e.isButton && Input.anyKeyDown) {
		Debug.Log(e.keyCode.ToString());
	}
}

I couldn’t find anything in Event for joysticks. What do other people do?

There are no events for joysticks - you’ll have to iterate through all buttons.