GUI controlled by keyboard

Hello!

My question is very simple. I have a GUI button “Play” and I want the player to be able to press it by hitting a key (and not using the mouse). There are no other options-there is only one button and the player will hit it.

Thanks!!

well i was thinking cant you just add inputs??? and trough a script define that when input spacebar is pressed set GUI awake :slight_smile: well thats what i would do im not shure if thats the best or the right way to do it but i gess its something:)…i would help you with the script but i still havent mastered scripting:(…ohhh the imput menu is in
Edit—>ProjectSetings–>input

you can make a label look like a button with gui styles, then in the update function have a if key down command.

I guess you’re using UnityScript?

function OnGUI()
{
    var e = Event.current;
    if (GUILayout.Button("Play") || (e.type == EventType.KeyDown && e.keyCode == KeyCode.Return))
    {
        // Start the game
    }
}

If you want any key to start the game just remove the keycode check :wink:

Thank you all very much!

Bunny83 your comment was so straightforward and easy to implement. Thanks again.