- Home /
How can a Save a HighScore
I have made a version of the Runner Game from Cat Like Tutorials and i was wondering if anyone here could please provide me with an example on how to save. I have heard of playerprefs but dont know how to use it
Unity does come with documentation; did you try reading it?
Answer by hirenkacha · Aug 06, 2012 at 08:00 AM
You will have a score variable, which will calculate the score in game and will compare it with playerprefs with key "highscore". If it is higher then it will store the score to the PlayerPref using PlayerPrefs.SetInt("highscore",score);
this statement will store value of score in highscore PlayerPref. To retrieve the highscore you can use PlayerPrefs.GetInt("highscore")
.
if(score > PlayerPrefs.GetInt("highscore"))
{
PlayerPrefs.SetInt("highscore",score);
}
Answer by Daryn · Aug 06, 2012 at 04:53 PM
I was hoping for one that would save so that if i disabled play and then clicked it agian it would still be there.Incase that is soppose to do that and i made a mistake here is my line for it(and yes i know i have diffrent variables)
void GameOver () { if(highestScore > PlayerPrefs.GetFloat("bestScore")){ PlayerPrefs.SetFloat("bestScore",highestScore); } }
It will definetly store the score but after you finished with building the game. Not while playing it in unity.
I have already done this in my android device and working fine.
Your answer
Follow this Question
Related Questions
Saving with PlayerPrefs? How it works? 1 Answer
Saving and loading game with PlayerPrefs 1 Answer
How do you save timer with PlayerPrefs? 1 Answer
Having issues with PlayerPrefs... 2 Answers
Save Datasets at runtime 2 Answers