September 2010
Beginner
384 pages
8h 49m
English
The very last thing we need to do is to add a button to the end of the game so that the player can play again. Let's revisit our good friend GUI from the last few chapters.
Add the OnGUI function to the HeartBounce script:
function OnGUI(){
if(hasLost){
var buttonW:int = 100; // button width
var buttonH:int = 50; // button height
var halfScreenW:float = Screen.width/2; // half of the Screen width
var halfButtonW:float = buttonW/2; // Half of the button width
if(GUI.Button(Rect(halfScreenW-halfButtonW, Screen.height*.8, buttonW, buttonH), "Play Again"))
{
numHits = 0;
hasLost = false;
transform.position = Vector3(0.5,2,-0.05);
rigidbody.velocity = Vector3(0,0,0);
}
}
}
For GUI pros ...
Read now
Unlock full access