Best time scoring system

Hey guys,

I have made a timer in my game but at the moment im trying to set up a scoring system based on best time, like a racing game, this is the script i have for the timer at the moment. any help would be much appreciated thanks.

code#

var startTime = 0;

function Update () {
//The time taken so far
timeTaken = startTime + Time.time;
// Format the time nicely
guiText.text = FormatTime (timeTaken);

}

//Format time like this
// 17[minutes]:21[seconds]:05[fraction]

function FormatTime (time)

{

var intTime : int = time;
var minutes : int = intTime / 60;
var seconds : int = intTime % 60;
var fraction : int = time * 10;
fraction = fraction % 10;

//Build string with format
// 17[minutes]:21[seconds]:05[fraction]

timeText = minutes.ToString () + “:”;
timeText = timeText + seconds.ToString ();
timeText += “:” + fraction.ToString ();
return String.Format(“{0:00}:{1:00}:{2:00}”, minutes, seconds, fraction);
}

code#

It seems like your over complicating things, imma try to explain a way to make what you wantmore smipler.
Ok so we know there is 60 minutes in an hour. So you could set up a time system to make when minutes is equal to or greater than 60 increment hour, as for minutes we know there is 60 seconds in a minute so the same concept would take effect and a simiular method would go for seconds. So to put it simple when 60 seconds pass you reset seconds to zero and increment the minutes every time 60 seconds pass, when the minutes become 60 you reset them and increment the hour, to display this you just display each different time variable on one line seprated by the “:” character. Hope that helps explain, perhaps when I get more free time I will code you a working timer if you still dont get the concept.

hey buddy,

Thanks for the reply I totally understand what your saying it makes perfect sense, however the timer i have works fine its just im trying to get a high score system from the time if that makes sense. so once the player reaches the end it saves his time.

So just create a statement to check highest time?

if (newTime > bestTime) { // save time }

GRIM beat me to it but what he said is what i said below…

ok just make a variable to store the time, and display it. and then if it is a time trial and they attempt to beat the score make another variable to store the current time, and compare it to the old time and display it. such as

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 logic is quite simple. if you wanted to display the previous top 3 times make a variable such as

var previousBestScore

and set it to equal bestScore