Thursday, 13 January 2011

Unity GUI

Making Controls with UnityGUI

UnityGUI controls make use of a special function called OnGUI(). The OnGUI() function gets called every frame as long as the containing script is enabled - just like the Update() function.

GUI controls themselves are very simple in structure.

The script function looks like this...

function OnGUI () { GUI code goes here }

creating a simple button.

function OnGUI () {

// Make the first button. If it is pressed, run event
if (GUI.Button (Rect (20,40,80,20), "Click Me")) {

How the code works...

adds a button element
Rect (20,40,80,20)
The first two numbers are the x and y coordinates.
The second two are width and height.
"Click Me"
This is the text you want on your button.

*Note the if at the beginning makes it run a script when clicked.

useful GUI Link

No comments:

Post a Comment