
Unity 4.x Game Development by Example: Beginner's Guide
By :

Let's create one of these Automatic Layout areas in our GameScript.
We don't need the Update
function in this script. As we did earlier, change Update
to OnGUI
to create an OnGUI
function:
function OnGUI () {
Begin and end the automatic layout area inside the OnGUI
function:
function OnGUI () { GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height)); GUILayout.EndArea(); }
The area will be the width and height of the screen, and it will start at the screen origin at the top-left of the screen.
These two statements are like bookends or HTML tags. Any UI controls we build between these bookends will be created within the area we defined. Each new control will automatically stack vertically beneath the last. The controls will stretch to the width of the area, which in this case is the entire screen.
If you'd like to stray off the beaten path and build a few buttons between the area...
Change the font size
Change margin width
Change background colour