Time Score?

Okay, this is the only thing that is hindering the completion of my game. I have a timer script:

#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
}

The player’s job in my game is to tap each of the spawning stars to destroy them, and if they let one pass a certain point they lose the game. The Timer is there to basically see how long each player can last.

I’ve tried, but I cannot seem to save the timer score and display on the GameOver Scene. How do I go about this? Could you please explain in a step by step way.

The script you posted is malformed and busted, this can’t be what you are working with? The last if statement is outside of any function/method, are you saying you used this and it didn’t create a build error in unity?

@Landern I think he’s added his psuedo code into his script…

@OP
move the functionality from this line

var guiTime = Time.time - startTime;

to the Update function (you’ll need to sort out variables and stuff to make this work)… then you can handle the “isplaying” “gameover” etc. states. If you leave it in the OnGUI function it’ll keep adding time to the total even when the player has entered gameover.

OnGUI should work out how to display information which is being worked out elsewhere.

There is no error. The timer works fine.

I’ll see where I’ll get. Thank You.