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 in C#:
Bad news first: button rollover (changing the GUIStyle state from normal to hover) happens only when mouse-overing the button. This is the “hardcoded” behaviour of Unity Engine and you cannot manipulate it.
But there is a way to affect the display (though not using the GUI.Button). You could use the GUIStyle.Draw method. You should supply the rectangle and GUI.Content, plus a few of the boolean values indicating the GUIStyle state.
Note that this way you cannot get the “immediate mode” state of “is the button clicked with mouse” but you should do your own mouse calculation to see if it has been clicked using the mouse.