This question was
closed Mar 22, 2017 at 03:28 PM by
AlexStf for the following reason:
The question is answered, right answer was accepted
Question by
AlexStf · Mar 20, 2017 at 02:54 PM ·
c#unity 5scripting problemscripting beginnerc# tutorial
Highscore shows 0 upon restart, and the correct highscore appears again once the player scores 1 point
i know it's a simple scrip issue, but in new around here and can't seem to figure it out thank you in advance Here is my script`void Awake () { this.highscore = PlayerPrefs.GetInt("HighScore"); PlayerPrefs.Save (); if (instance == null) { instance = this; } else if (instance != this) { Destroy (gameObject); }
}
void Update ()
{
if (gameOver == true && Input.GetMouseButtonDown (0))
{
SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);
}
}
public void BirdScored()
{
if (gameOver)
{
return;
}
score++;
if (score > highscore)
{
highscore = score;
PlayerPrefs.SetInt("HighScore", score);
}
Score.text = "Score: " + score.ToString ();
Highscore.text = "HighScore: " + highscore.ToString ();`
Comment
Answer by aFeesh · Mar 20, 2017 at 05:41 PM
In the Awake() method add Highscore.text = "HighScore: " + highscore.ToString ();
under the line this.highscore = PlayerPrefs.GetInt("HighScore");