Game Development Reference
In-Depth Information
The example will draw the box background and the
Label
,
Text
, and
Button
controls
on top of the box area and looks like this:
The box control can be useful to highlight groups of controls or providing a simple
background (alternatively, you can use an image instead of just text and color).
As with the other controls, the
Box
control supports styling using
GUIStyle
.
The Toggle/checkbox control
If checking on / checking off is your thing, then the legacy GUI also has a
checkbox
control for you, useful for those times when you need to visualize the
on/off
state
of an option.
Like the
TextField
control, you pass the variable that manages
Togglestate
as
a parameter and it returns the new value (if it changes), so it is applied in code
as follows:
bool blnToggleState = false;
void OnGUI() {
blnToggleState = GUI.Toggle(new Rect(25, 150, 250, 30),
blnToggleState, "Toggle");
}
This results in the following on-screen result:
As with the
Label
and
Button
controls, the font of the text displayed can be altered
using either a
GUIStyle
or
guiText
GameObject property.