- Home /
The question is answered, right answer was accepted
Time difference between race time and best time
Hello!
I'd like to show, when the race is finished, what the difference is between the race time and the players best time. If the time is better than the previous time, then show the text in green color and vice versa when worse then red color.
How do I do that with float variables?
public bool finished = false;
public float raceTime = 0;
public float bestTime = 0;
if (finished && !PlayerPrefs.HasKey ("Best time 11") || finished && raceTime < bestTime) {
bestTime = raceTime;
PlayerPrefs.SetFloat ("Best time 11", bestTime);
} else {
bestTime = PlayerPrefs.GetFloat ("Best time 11", bestTime);
}
Can you give us more details?
The problem is do a 3D text? Or calculate the time?
You had to do PlayerPrefs.Save on Destroy, too
The problem is the calculation as I can't just raceTime - bestTime like I would do with integers.
Why you can't?
float a = b - c;
This sentence is possible and is correct too
Answer by InvincibleCat · Feb 10, 2015 at 08:00 PM
if (finished)
{
if(raceTime < bestTime)
{
bestTime = raceTime;
PlayerPrefs.SetFloat ("Best time 11", bestTime);
//set color text in green
}
else
{
bestTime = PlayerPrefs.GetFloat ("Best time 11", bestTime);
}
}
Hope that help.
Cheers
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Problem calculating time taken to complete level 1 Answer
Making a Timer Out out of 3D Text using C#. 1 Answer
Start timer on mouse0 click 1 Answer