Question by
IamUnityAddict · May 08, 2017 at 09:32 AM ·
unity 5
How to set and save individual high scores for each scene
How to set and save individual high scores for each scene
for example i have 3 scenes
Scene A Scene B Scene C
void Start () {
if (PlayerPrefs.HasKey("HighScore"))
{
highScoreCount = PlayerPrefs.GetFloat("HighScore");
}
}
void Update () {
if (scoreCount > highScoreCount)
{
highScoreCount = scoreCount;
PlayerPrefs.SetFloat("HighScore",highScoreCount);
}
Comment
Best Answer
Answer by UnityCoach · May 08, 2017 at 11:11 AM
You could have a current level index as a static value and use this along with HighScore.
private int currentScene = 0;
void Start ()
{
if (PlayerPrefs.HasKey(currentScene.ToString() + "_HighScore"))
{
highScoreCount = PlayerPrefs.GetFloat(currentScene.ToString() + "_HighScore");
}
}
You could also store high scores as a delimited string. "0, 125, 240" and parse it with String.Split().
Your answer
![](https://koobas.hobune.stream/wayback/20220612121532im_/https://answers.unity.com/themes/thub/images/avi.jpg)