Time for action – create an area to store the grid
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, changeUpdate
toOnGUI
to create anOnGUI
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.
Have a go hero – don't take my word for it!
If you'd like to stray off the beaten path and build a few buttons between the area...