Displaying high score on another scene and saving high score
So I have been fiddling with this for a few days now and everything I have read on this site and everything I have read from the documentation makes sense and I believe I am doing it right but it isn't working. So you have the main game where you get the score and when you start the game it should show that score on the screen. I have tried everything I can think of and it isn't working please. help.
public class ScoreKeeper : MonoBehaviour {
public float distanceTravelled = 0;
Text text;
private static bool isDead;
public static float finalDistance;
void Start(){
text = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
if (Death.isDead == false) {
distanceTravelled = distanceTravelled + 1;
text.text = "Score: " + distanceTravelled;
} else {
distanceTravelled = distanceTravelled;
finalDistance = distanceTravelled;
PlayerPrefs.SetFloat("High Score", finalDistance);
}
}
}
This is the class where the store displays in the main game and it works, you can see your score going up and I assume I am saving it with PlayerPrefs.
public class HighScoreKeeper : MonoBehaviour {
private float highScore;
private static float finalDistance;
Text HighScoreText;
void Start () {
HighScoreText = GetComponent<Text> ();
if(ScoreKeeper.finalDistance > highScore){
highScore = ScoreKeeper.finalDistance;
HighScoreText.text = "Highscore: " + PlayerPrefs.GetFloat("High Score");
}
}
}
Here is the script that is on my text item on interface for the text item. Right now that item reads High Score but I want it to show the actual high score and I want it to save on exit so it will always be displayed and be replaced by other high scores. Any help is greatly appreciated.
Answer by incorrect · May 04, 2016 at 07:43 PM
Check this live training. PERSISTENCE - SAVING AND LOADING DATA
Your answer
Follow this Question
Related Questions
how do i store highscore locally C# (SIMPLE) 3 Answers
Highscore not working 0 Answers
Help making a high score with player prefs/displaying it 1 Answer