Game Development Reference
In-Depth Information
//Creating a Local Hiscore Object
obj_localHiScore = new LocalHiScore();
//Setting the maximum scores to show on the table & loading the
local high score data here
obj_localHiScore.SetMaxUser(maxUsers);
}
In this Start() funcion, we created the new LocalHiScore object, and set the
max user display and load the user data from the local machine.
10. We already have the user data object, and now we need to save the score by going
to the GameoverPage() funcion inside the Submit button funcion and type
the following highlighted code:
//Submit button
if (GUI.Button(new Rect((Screen.width - 240)*0.5, (Screen.
height*0.1) + 200, 240, 30), "SUBMIT")) {
b_isClickSubmit = true;
//TODO: Submitting both local and server high score here
obj_localHiScore.SaveGame(TimeScoreUI.int_currentScore,
userName); //Submitting to the local score
}
11. This is the code for saving the score locally after the player clicks on the SUBMIT
buton. Then, we save the score to our local machine. Now we need to load the
user score data and display it on the menu in the scrolled area by going to the
LocalScorePage() funcion and adding the highlighted code as follows:
//Loading the local scores
private function LocalScorePage() : void {
//Creating the background box
GUI.Box(new Rect(Screen.width*0.1, Screen.height*0.1, Screen.
width * 0.8, Screen.height * 0.8), "LOCAL HI-SCORES", GUI.skin.
GetStyle("Box2"));
//Creating the scrolled area and scrollbar to view the player
scores
scrollPosition = GUI.BeginScrollView (new Rect ((Screen.width -
320)*0.5, (Screen.height*0.1) + 80, 320, 180), scrollPosition, new
Rect (0, 0, 300, 30*maxUsers));
for (var i: int = 0; i < maxUsers; i++) {
//Set the number of the user
GUI.Label(new Rect(0, i * 30, 35, 30), (i+1).ToString() +
".");
//TODO: Showing the user name and score here
GUI.Label(new Rect(35, i * 30, 120, 30), obj_localHiScore.
GetNameData(i));
 
Search WWH ::




Custom Search