Game Development Reference
In-Depth Information
{
//make this one the winner
winner = collision.gameObject.name;
}
}
function OnGUI ()
{
if(winner ! = "")
{
GUI.BeginGroup (Rect (Screen.width / 2 − 100,
Screen.height / 2 − 100, 200, 200));
GUI.Box (Rect (0,0,200,200), "Game Over");
GUI.Label(Rect (20,20,200,100), "Winner: " + winner);
if(GUI.Button (Rect (50,60,100,30), "Play Again"))
{
//reset the game
winner = "";
GameObject.Find("Car Prefab").transform.
position = playerLocation;
GameObject.Find("Player2").transform.
position = npcLocation;
GameObject.Find("Player2").
GetComponent("waypoints").
currentWP = 0;
}
GUI.EndGroup ();
}
}
function Update () {
}
Step 14. The preceding script uses the name of the colliding object
to display the winner on the screen. Currently, both the Car Prefab
and the Player2's elements are named the same. Select each chassis
collider in the Hierarchy and give them different names in the
Inspector.
Step 15. Play. But be ready for a quick restart when you click
on Play Again.
We will leave this hands-on session at this point. When artificial
intelligence is introduced later in the topic, we will return to look
at modifying the behavior of the NPC.
Search Nedrilad ::




Custom Search