- Home /
GUI.Button's status react to keyboard event?
Sorry if this is answered elsewhere, I can't seem to find any answer to this. I apologize in advance for my bad english.
I managed to figure out how to use the keyboard to press a GUI.Button, but I can't seem to make the button react the same way with the keyboard like when I click it with a mouse.
The part where the button changes from Normal to Hover to Active when a mouse click is detected or held. I want it to do the same when the key is pressed on the keyboard. This is the current code I have:
if (GUILayout.Button("Skill") || e.isKey && e.keyCode == KeyCode.Alpha1) {
if (goldCost[0] < goldAmount && buttonCooldown == true){
buttonCooldown = false;
startButtonCDTime = Time.time + 1;
goldAmount -= goldCost[0];
Instantiate(Resources.Load(Player));
}
}
Perhaps if a GUI.Button doesn't work I should be using GUI.Texture or GUI.Box? or maybe there's a way with GUI.FocusControl?
Btw...I've read somewhere that the Input class might cause error when used in OnGUI and that using the Event class is better, is that true or out-dated? Link to source: http://answers.unity3d.com/questions/242309/main-menu-keyboard.html