This is the last thing that I need to do, and my game will be finished. I already have my game over trigger, which is basically the star dropping down to a certain coordinate.
What’s bothering me now is saving the player’s best time and showing it on the Game Over scene. How do I do it. I was previously told to create a static variable which will let be able to reference it from my Game Over scene. How do I do this as well?
Here are my scripts.
Timer:
#pragma strict
private var startTime : float;
var textTime : String;
//First define two variables. One private and one public variable. Set the first variable to be a float.
//Use for textTime a string.
function Start() {
startTime = Time.time;
}
function OnGUI () {
var guiTime = Time.time - startTime;
//The gui-Time is the difference between the actual time and the start time.
var minutes : int = guiTime / 60; //Divide the guiTime by sixty to get the minutes.
var seconds : int = guiTime % 60;//Use the euclidean division for the seconds.
var fraction : int = (guiTime * 100) % 100;
textTime = String.Format ("{0:00}:{1:00}:{2:00}", minutes, seconds, fraction);
//text.Time is the time that will be displayed.
GetComponent(GUIText).text = textTime;
}
var bestScore = 0;
var playerTime = 0;
//When the race is completed;
bestScore = playerTime;
//Reset playerTime to zero
//Display the best score(Score to beat)
//If the next drivers playerTime is higher than the previous bestScore
if(playerTime > bestScore){
//Display the new best score.
//Reset playerTime to zero
}
Game Over:
function Update () {
if(transform.position.y < -2.6){
GameOver();
}
}
function GameOver(){
Application.LoadLevel("Game Over");
}