- Home /
Highscrore won't work
Hello, so recenlty I have made my high score works well...but yeah it doesn't. When the game is over it saves me high score for example 5. When i re-play it in debuging in unity it says "Highscore:5" that is all right! but if i get score 1 and game is over highscore will set to 1. That is just not logic. Please help me. This is my code for high score: public int highscore; void GameOver() {
if (i > highscore) {
GUIText highScoreObject = GameObject.Find ("HighScoreObject").GetComponent<GUIText> ();
highScoreObject.text = "Highscore: " + PlayerPrefs.GetInt("highscore", highscore);
highscore=i;
PlayerPrefs.SetInt("highscore", highscore);
PlayerPrefs.Save();
}
}
And i am calling this function here:
if (life <= 0) {
GameOver();
Start ();
}
Answer by wijesijp · May 29, 2014 at 10:06 AM
The problem is you need to get your hi score loaded to "highscore" before comparing it
highscore = PlayerPrefs.GetInt("highscore");
if (i > highscore)
{
GUIText highScoreObject = GameObject.Find("HighScoreObject").GetComponent<GUIText>();
highScoreObject.text = "Highscore: " + i;
highscore = i;
PlayerPrefs.SetInt("highscore", highscore);
PlayerPrefs.Save();
}
Ohh Thanks to you now my game is working :) I just need some fixes maybe you would know them? :) can i contact you anywhere else? :)
Your answer
Follow this Question
Related Questions
Save/Load Variable with playerprefs 1 Answer
How can i save a int for multiple texture. Please Read. 0 Answers
PlayerPrefs script problem 2 Answers
How to save resources configuration file for unity3d? 0 Answers
DeleteAll not working on android? 0 Answers