O'Reilly logo

Unity 3 Game Development HOTSHOT by Jate Wittayabundit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

OnGUI

OnGUI is called for rendering and handling GUI events, such as GUI.Button, GUI.Label, GUI.Box, and so on.

This means that your OnGUI implementation might be called several times per frame (one call per event). If the enabled property of MonoBehaviour is set to false, OnGUI will not be called.

Example

// Draw the Button (width = 150, height = 50) at the position x = 10, y = 10. 
function OnGUI () {
  if (GUI.Button(Rect(10, 10, 150, 50), "My Button")) {
    Debug.Log("Hello World");
  }
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required