Game Development Reference
In-Depth Information
var totalBalls =
scoringObjects[0].GetComponent("countBalls").
totalBalls +
scoringObjects[1].GetComponent("countBalls").
totalBalls +
scoringObjects[2].GetComponent("countBalls").
totalBalls +
scoringObjects[3].GetComponent ("countBalls").
totalBalls;
if(totalBalls > = maxBalls)
{
PlayerPrefs.SetInt("LastScore",score);
Application.LoadLevel("gameover");
}
}
Step 25. The aforementioned code adds together the balls in each
beaker. However, each beaker does not currently keep its own
count. To fix this, open countBalls.js and update as shown in
Listing 4.14 .
Listing 4.14 Code to Make Each Beaker Keep a Count of Balls
That Have Entered
var colorMatch:Material;
var score: int = 0;
var totalBalls: int = 0;
function OnTriggerEnter (obj : Collider)
{
if(obj.gameObject.renderer.material.color == colorMatch.
color)
{
score = score + 1;
}
totalBalls++;
}
Step 26. If you don't want to wait until you've caught 20 balls to
check your handiwork, change the value of 20 in score.js to a lower
value.
Step 27. Open the mainmenu scene and test out your game.
Search Nedrilad ::




Custom Search