Hello everyone,
I have a running timer in my app and when user collides with an object, the timer saves itself as high score.
Everything is working fine for now.
However, when i pass my high score, the high score text shows itself as Number.number
When i cannot pass the latest highscore, it shows itself as only Number.
I do not want it to show as number.number everytime user breaks his record. Only with number.
I would be grateful if you could help me. I have played with ToString options but could not make it happen.
BTW, this script works alright for timer and high score. I hope it would be useful for anyone.
public Text timerText;
public Text highscore;
private float startTime;
void Start()
{
startTime = Time.timeSinceLevelLoad;
highscore.text = "High Score : " + PlayerPrefs.GetFloat("HighScore").ToString("0");
}
void Update()
{
float t = Time.timeSinceLevelLoad;
if (t > PlayerPrefs.GetFloat("HighScore", 0))
{
PlayerPrefs.SetFloat("HighScore", t);
highscore.text = "High Score: " + t;
}
startTime += Time.timeSinceLevelLoad - startTime;
string seconds = (startTime % 60).ToString("0");
timerText.text = seconds;
}