- Home /
GUI using keyboard as input?
I'm trying to make a main menu using the arrow keys and the enter key (enter) as inputs instead of the mouse. I'm using a ball to act as a selector and using box colliders to act as trigger when the player presses the return button (Example: I used 3D text "Start" and I added a box collider and set it to trigger and adjusted its size so that when the player moves the ball into the collider then he can select "Start".
I wrote this code so when the player presses the return key while inside the collider then Unity would write a message saying "Start Game"
`function OnTriggerEnter(col : Collider){ if(col.gameObject.tag == "Quit" && Input.GetKey(KeyCode.Return)) { Debug.Log("Have quit"); } else if(col.gameObject.tag == "Start" && Input.GetKey(KeyCode.Return)) { Debug.Log("Start Game"); } }`
Instead of Unity displaying "Start Game" or "Have Quit" once I press the return while inside one of the colliders, Unity only displays the message when I enter the collider while holding down the return key.
Please help and thanks in advance :)
Your answer
Follow this Question
Related Questions
GUI Button keyboard? 3 Answers
A node in a childnode? 1 Answer
Mobile keyboard not showing on unity remote 1 Answer
my camera zooms when I hit the arrow keys - not sure how to disable 1 Answer