- Home /
How do you make a Main Menu that only takes Joystick input and is not affected by the Cursor
I have setup a main menu using the Canvas UI, buttons and text based upon the Unity 5 tutorials: https://unity3d.com/learn/tutorials/topics/user-interface-ui
In the EventSystem I have set First Selected to the Play Button that I created. When the Menu begins the Play Button is selected allowing the player to navigate through the other buttons on the menu via the left stick on an Xbox controller. The problem is that if the player clicks on the game window using the mouse, but not on a button, then it makes the button currently highlighted no longer highlighted thus making navigation on the menu impossible with a controller.
I have tried hiding the cursor and locking it to the center but that does not prevent the mouse click from deselecting the button currently highlighted.
Is there a way to prevent the cursor from interfering with the joystick input or at least allow a button to stay highlighted despite clicking in the game window and not on a button?
Answer by Vice_Versa · Sep 04, 2015 at 09:05 PM
not sure if what youre trying to do is actually possible. generally, when i make a nonstandard interface, i dont use the GUI objects, i use regular GameObjects then code in everything myself for selection and hoveranimations.
Thank you Vice Versa for your quick reply. If there is no alternative method of going about doing this then I would love to hear your approach using GameObjects as buttons. Looking at this method I already see that I would need to somehow implement the following:
Pointer (keep track of what is currently highlighted)
An array of some sort (store all the other buttons)
Hovering state ("button" currently selected)
Normal state ("button" not selected)
Pressed state ("button" clicked)
I have had no experience in doing anything like this and would appreciate some tips or additional advice to send me towards the right direction.
if any alternative methods come up I would be more than grateful to hear them. thank you again for your time.
Answer by CCV334 · Sep 05, 2015 at 08:07 AM
A current solution I have is the following:
Hide the cursor using
Cursor.visible = false;
Create a completely transparent Panel in front of the canvas used to prevent the cursor with interfering with the buttons
Reload the scene if there is any mouse input:
if (Input.GetMouseButtonDown(0)) { Application.LoadLevel(Application.loadedLevel); } if (Input.GetMouseButtonDown(1)) { Application.LoadLevel(Application.loadedLevel); } if (Input.GetMouseButtonDown(2)) { Application.LoadLevel(Application.loadedLevel); }
I'm still open to suggestions but for now this will suffice.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
XBox Controller Joystick-Driven Mouse Cursor in Unity 0 Answers
Joystick buttons don't reset on application start 1 Answer
How to know if finger is on joystick if it is at horizontal & vertical zero 0 Answers
How to have multiple types of controller input using the input manager 0 Answers