- Home /
Why is checking button click in Unity done this way?
I find the Unity way of writing the GUILayout.Button in onGUI to check for button click to contract the way I am used to seeing UI code, in which you instantiate a UI object and set up a click event handler for it. What's the reasoning behind doing it this way (from a framework creator's viewpoint)?
function OnGUI {
if (GUILayout.Button("Play")) {
// button clicked
}
}
I think this site is more for "how" questions than "why" questions. But I also think OnGUI is the event handler, and it's already been set up, internally. Right? So there you go.
I would assume its faster to check for the buttons that you are interested in as needed, rather than scanning all input and firing individual methods, but I could be wrong.
Answer by Eric5h5 · Sep 03, 2012 at 10:47 PM
OnGUI is immediate mode. If you want something else, use GUITextures (which can use the OnMouseDown function), or wait for the new GUI system in Unity 4.something.
Your answer
Follow this Question
Related Questions
Automatic Wrap 2 Answers
GUI Button sound problem, don´t work 1 Answer
GUI.button Texture shows up in Unity but doesn't show on android device. 1 Answer
GUI Button no response 1 Answer
Whats wrong with my GUI.Toggle? 2 Answers