Game Development Reference
In-Depth Information
Figure 17.2 Placed closing GUI
elements.
Why?
Really, the additional functionality for these two buttons could be
appended to the OpenSceneButtonScript, and generally, in my own
projects in the name of fewer scripts, this is how I would do it (and
rename the script GUIButtonsScript). However, in the format of a topic,
this starts to again become a really long script and can sometimes be
difficult to see how it all works with the extra script. So for clarity's sake,
we'll make a new script.
Step 6: Get rid of the variables and Awake function (neither are
needed here) and adjust the OnMouseDown function to check for the
name of the buttons being clicked. If the Button-Exit is clicked, quit
the game. If Button-PlayAgain is chosen, load the level Scene-Opening.
Finally, make sure that the mouse is free when the level starts (we'll be
entering the CloseScenes after playing other levels that may be locking
the cursor):
function Start(){
Screen.lockCursor = false;
}
function OnMouseEnter () {
guiTexture.color = Color (1,1,1);
}
function OnMouseExit (){
guiTexture.color = Color (.2,.2,.2);
}
function OnMouseDown(){
if (name == “Button-Exit”){
Application.Quit();
}
Search WWH ::




Custom Search