Game Development Reference
In-Depth Information
OnGUI()
The OnGUI() function is called to render and handle GUI events, such as GUI.Button ,
GUI.Label , and GUI.Box .
This means that your OnGUI() implementation might be called several times per frame
(one call per event). If the MonoBehaviour object is enabled and is set to false ,
OnGUI() will not be called.
An example of OnGUI() is as follows:
// JavaScript user:
//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");
}
}
// C# user:
//Draw the Button (width=150,height=50) at the position x =
10, y = 10.
void OnGUI () {
if (GUI.Button(new Rect(10, 10, 150, 50), "My Button")) {
Debug.Log("Hello World");
}
}
Search WWH ::




Custom Search