Xbox Controller and Unity 5 menu

I’m trying to control a menu with an xbox controller. Any idea how to do this?

You are going to want to check out the Event System and UI element Navigation.

When you add a UI element or canvas to the scene/hierarchy, Unity automatically adds an object for the EventSystem that will look something like this in the inspector:

44240-eventsystem.png

This object contains a few scripts, including one for the Standalone Input Module. This defines what axes and buttons are used for navigation within the canvas’s navigation. These axes and buttons are directly from the Input Manager, so you may need to set up new axes for your controller in the Input Manager.

By default the Unity input manager is not set up to support the Xbox 360 controller. You can use this wiki page with the Xbox 360 controller axis and button mappings to help you get your axes and buttons set up how you like them.

I really recommend Unity’s tutorial video on the Event system if you are new to using the UI system’s events. It does a thorough job of explaining how to connect elements and navigation between them works.

Unity 5 is more or less ready to go as far as the Xbox 360 controller goes, but you’ll need to do a little work in your UI code.

The trick is that you have to select an object before anything will work. If you have just one screen of buttons in your scene, you can drag the first button into the “First Selected” field of the “Event System (Script)” section of the EventSystem object that is auto-added by Canvas. If you have additional screens, you’ll need to tell the UI system where to start.

The method to use is Selectable.Select() (which currently has the awesomely accurate description, “Selects this Selectable”). UI Button objects are Selectable. Once you call this, the navigation system will have a starting point, and moving the controller joystick will move the selection around.

To change the way the selection moves, play with the Navigation settings on the UI Buttons.

(FWIW, I’ve found that you can select a button manually while playing in the Unity Editor by putting your mouse pointer on the button, clicking the mouse, moving the pointer off of the button, and then releasing the mouse button. Do that, and you should then be able to navigate the current screen with the controller and ‘A’ button, as well as the arrow keys and space bar.)

See also this question.

Maybe you can try using store assets: