how do i add timer for score and the highest time the timer reached as my high score?

Updated on October 30, 2017 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on October 30, 2017

how do i add timer for score and the highest time the timer reached as my high score?
this is what i have tried but i am getting errors anyone want to help?

public class Timer : MonoBehaviour {
public Text timertext;
public Text highscore;

private float starttime;

// Use this for initialization
void Start () {
starttime = Time.time;
highscore = PlayerPrefs.GetFloat(“HighScore”, 0).ToString; }

// Update is called once per frame
void Update () {
float t = Time.time – starttime;

string minutes = ((int)t / 60).ToString();
string seconds = (t % 60).ToString(“f2”);
timertext.text = minutes + “:” + seconds;
PlayerPrefs.SetFloat(“Highscore”, timertext.text);
}
}

  • Liked by
Reply
1 on October 30, 2017

What is the error that you get? And you should probably not overwrite the high score value each update. And in the line PlayerPrefs.SetFloat(“Highscore”, timertext.text) timertext.text is not a float, so that won’t work.

on October 30, 2017

bro the problem is that the timer counts up every time my player starts and dies it resets the time to 0 but i cant get the timer to save to the high score and every time it passes the high score to save it each time. when i change the timertext.text to a float the whole timer stops working and i cant find a way to add the timertext.text to another float.

Show more replies
  • Liked by
Reply
Cancel
0 on October 30, 2017

okay i fixed my own problem after fucking trying forever thanks 😀 now i can update it like a bows.

  • Liked by
Reply
Cancel