time trial question

hey guys

im making a car game and i wanted to know how to achieve a time trial (best time) script in javascript if possible.

i have a scene called "race01" and a collider that stops the timer when the car finishes the race.

i have another scene called "best time" that i want to display the best time done in the race.

the timer resets everytime the scene is load.

my question is : how can i make a variable or function that keeps track of the best time so that i can display it as a " best time record" in the other scene.

thx

There are lots of ways to do timers. Using Unity's Time class is one way. To store the record time, you would simply write that to a variable.

var record : float = Mathf.Infinity;
private var startTime : float = -1.0f;

function StartTimer() {
    startTime = Time.time;
}

function StopTimer() {
    if(startTime > 0.0f) record = Mathf.Min(Time.time - startTime, record);
    startTime = -1.0f;
}

You could also try a System.Diagnostics Stopwatch in stead of Unity's time variable, but that's your call.