Game Development Reference
In-Depth Information
Listing 4.11 A Start Function That Loads Player Preference
and Uses It to Set the Difficulty of the Game
var ball:GameObject;
var materialArray: Material[];
function Start()
var playerlevel = PlayerPrefs.GetInt("Level");
if(playerlevel == 1)
GameObject.Find("Cube").transform.position.y = 0;
else if(playerlevel == 2)
GameObject.Find("Cube").transform.position.y = 2;
function Update ()
Step 17. Before playing, check that the white line cube you have used is
called Cube in the Hierarchy. If it is not, change the name in the script by
replacing the text “Cube” with the name you used. Play. The main menu
buttons now set the level of difficulty that changes the height of the white
line. The higher it is, the harder the game becomes.
Step 18. Finally, we want to add an end game scenario. To make it simple, we
will have the game end after 20 balls have been caught. First, create a new
scene with File > New Scene. After the scene opens select File > Save Scene
and call it gameover . A scene icon with this name will appear in the Project.
Step 19. Download Chapter Four/gameover.png from the Web site
and add it to the Project.
Step 20. Create a new JavaScript file called showScore.js and add
the code in Listing 4.12 .
Listing 4.12 Displaying a Gameover Screen with the Score
var goImage: Texture2D;
function OnGUI ()
var scoreText = "You Scored " +
Search Nedrilad ::

Custom Search