Game Development Reference
In-Depth Information
Let's add the two buttons before hooking the new GUI up to actual scene events.
In the OnGUI function, below the Label line, add
11.
// Play Again
if (GUI.Button( new Rect (Screen.width / 2 - 325, Screen.height / 2,300,60),
"Play Again")) {
// call function here
}
// Quit
if (GUI.Button( new Rect (Screen.width / 2 + 25, Screen.height / 2,300,60), "Quit")) {
// call function here
}
GUI Button controls are always waiting for a pick event, so they are wrapped in a conditional. Usually,
you will call a function if the pick event is detected. Once again, the pixel size and offset are specified in
the Rect. This time, because the text will always be the same, the strings are added directly to the code.
12.
Save the script.
13.
Click Play, and check out the changes in the game view. (Be sure to pick in
the window to change focus.)
The buttons are a nice size and well placed, but their visual appearance, though clean and elegant,
is not bold enough to stand out (Figure 10-9 ). The font size will require some adjustment, but this
time you will assign a texture to both the Normal and Hover parameters.
Figure 10-9. The newly added Button controls
 
Search WWH ::




Custom Search