I’m having a major issue with Unity’s GUI. I’m shooting a rocket whenever the player presses a GUI.Button. Here’s the problem, the button is only active when the button is released, not pressed. I want to run some code when the button is pressed, not released. Any ideas?
Unity buttons activate on a click and release because pretty all computer buttons work that way. To check for a click the “wrong” way, have to check the click and the area yourself:
You can check for the mouse clicked with Input.GetMouseButtonDown(0))
. Then if you look at Rect, it has an example in Contains: if (rect.Contains(Input.mousePosition))
. You’d check those in Update. Also note that mousePosition Y is pixels from the bottom, but a Rect for a GUI-button uses Y from top, so you may have to flip (Screen.height - y
).
Hm? AFAIK, GUI.Button already reacts to presses, not releases.
But take a look at Unity - Scripting API: GUI.RepeatButton
And please search Unity Answers before posting, similar questions have been asked before, and might have given you the hints you needed.