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;
}
}`
↧