Unity GUI 基础

Button

C#:

void OnGUI () {
        if (GUI.Button (new Rect (25, 25, 100, 30), "Button")) {
            // This code is executed when the Button is clicked
        }
    }

js:

function OnGUI () {
    if (GUI.Button (Rect (25, 25, 100, 30), "Button")) {
        // This code is executed when the Button is clicked
    }
}

RepeatButton

C#:

void OnGUI () {
        if (GUI.RepeatButton (new Rect (25, 25, 100, 30), "RepeatButton")) {
            // This code is executed every frame that the RepeatButton remains clicked
        }
    }

js:

function OnGUI () {
    if (GUI.RepeatButton (Rect (25, 25, 100, 30), "RepeatButton")) {
        // This code is executed every frame that the RepeatButton remains clicked
    }
}

Label

C#:

void OnGUI () {
        GUI.Label (new Rect (25, 25, 100, 30), "Label");
    }

js:

function OnGUI () {
    GUI.Label (Rect (25, 25, 100, 30), "Label");
}