- Home /
How do I get my endless runner high score,How do I make high score for an endless runner
Hello, the script works as far as keeping up with the score, however it doesn't save the high score as predicted. I would appreciate the help and Thank in advance.
public Transform player;
public Text scoreText;
public Text highScoreText;
private float score;
private float highScore;
void Start()
{
highScoreText.text = highScore.ToString();
highScore = PlayerPrefs.GetFloat("HighScore", highScore);
}
void Update()
{
scoreText.text = score.ToString("0");
score = player.position.z;
if (score > highScore) {
PlayerPrefs.SetFloat("HighScore", highScore);
highScore = score;
}
}
,This scripts works but however, it doesn't save the highScore on the UI. I would appreciate the help and Thank you in advance.`
public Transform player;
public Text scoreText;
public Text highScoreText;
private float score;
private float highScore;
void Start()
{
highScoreText.text = highScore.ToString();
highScore = PlayerPrefs.GetFloat("HighScore", highScore);
}
void Update()
{
scoreText.text = score.ToString("0");
score = player.position.z;
if (score > highScore) {
PlayerPrefs.SetFloat("HighScore", highScore);
highScore = score;
}
}`
Answer by antonsem · Jan 13, 2020 at 03:08 PM
You are not changing it in the ui. What you do is set the high score to the text, then read the high score in the Start().
What you want to do is read the high score first, then assign it to the text.
void Start()
{
highScore = PlayerPrefs.GetFloat("HighScore", highScore);
highScoreText.text = highScore.ToString();
}
Your answer
Follow this Question
Related Questions
Saving Times as Highscore 1 Answer
1st Problem: OnLevelWasLoaded, method is getting called twice. 2nd: Loading PlayerPrefs 1 Answer
playerprefs spawning errors. 1 Answer
i need to figure out how to add to a Player pref int 1 Answer
Im Doing HighScore System To My Game And There Is Something Wrong In My Scripts 0 Answers