Game Development Reference
In-Depth Information
GUI.BeginGroup (Rect (Screen.width / 2 − 100,
Screen.height / 2 − 100, 200, 200));
GUI.Box (Rect (0,0,200,200), goImage);
GUI.Label (Rect (55, 15, 100, 30), scoreText);
if(GUI.Button (Rect (25,165,150,30), "Back to Menu"))
{
Application.LoadLevel("mainmenu");
}
GUI.EndGroup ();
}
Step 21. Attach showScore.js to the Main Camera. Select the camera
in the Hierarchy and locate the script in the Inspector. Drag and drop
the gameover texture from the Project onto the goImage variable
in the script component.
Step 22. Play to check that it displays correctly.
Step 23. From the main menu, select File > Build Settings and click on
Add Current to add the gameover scene to the game build.
Step 24. Open score.js and change the code to check for a gameover
situation and to save the score before switching to the gameover
scene. This is given in Listing 4.13 .
Listing 4.13 Code to Gather a Total Count of Balls in Each Beaker
var score = 0;
var scoreStyle: GUIStyle;
var scoringObjects: GameObject[];
private var maxBalls:int = 20;
function OnGUI ()
{
score = 0;
for(var i = 0; i scoringObjects.length; i++)
{
score + =
scoringObjects[i].
GetComponent("countBalls").
score;
}
GUI.BeginGroup (Rect (Screen.width − 85, 5, 80, 80));
GUI.Box (Rect (0,0,80,60), "Score");
GUI.Label (Rect (0, 20, 80, 30),
String.Format("{0:0}", score),scoreStyle);
GUI.EndGroup ();
Search Nedrilad ::




Custom Search