- Home /
How to save the best score
I want to make a best score system thats something like flappy bird and those stuff. I've looked at a few tutorials, answers and forums for the PlayerPrefs thing but I still don't get what it is and how to use it so I decided to ask a question myself. Can anyone help me understand how to save the highscore and how to use PlayerPrefs? Thanks for your time.
Answer by smallbit · Aug 02, 2014 at 02:13 PM
Player prefs store data for you (in a file on android, in register on windows etc) so you can read it next time you launch the game. To store highScore you check if actual score after game ends is higher than highscore :
if(score>highscore)
{
PlayerPrefs.SetInt("HighScore",score);
}
But first you need to read it from prefs to local variable:
int highscore;
void Start(){
highscore=PlayerPrefs.GetInt("HighScore",0); //0 is default value here if player pref has not been stored yet (this only happend in first play assuming player will score at least 1 point)
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How To Add PlayerPrefs Scores? 1 Answer
Multiple choice game not working!?! 1 Answer
Script behaving too early 1 Answer
Nested Functions 1 Answer