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");
}
}