Problem in Saving Score?
Hey guys I have a game in which we have to pop bubbles and score points....And I have another scene in which I display the high score... And then each time the player score which is higher than the previous high score,... it gets updated....
And now the problem is How can I save that high score..?
This is the script which handles the currentScore.
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class ScoreHandler : MonoBehaviour { public static int currentScore;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
gameObject.GetComponent<Text> ().text = "score : "+currentScore;
if (currentScore >= HighScore.highscore) {
HighScore.highscore = currentScore;
}
}
}
//////////////////////////and this script handles the high score...
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class HighScore : MonoBehaviour { public static int highscore; // Use this for initialization void Start () { }
// Update is called once per frame
void Update () {
gameObject.GetComponent<Text> ().text = "high score : "+highscore;
}
}
both the text elements are UI text elements which are in the Canvas.
Soo,... How I can Save that high score..?
Answer by Sageose · Dec 20, 2015 at 07:10 PM
So is the issue saving it between scenes or between versions/new installations of the game?
Answer by LazyElephant · Dec 20, 2015 at 08:02 PM
You can save a high score using PlayerPrefs as shown in this question. http://answers.unity3d.com/questions/726178/how-do-i-use-playerprefs-to-save-my-score.html.
Alternatively, you could save it to a file. Both of these options are talked about in this live training session http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading?playlist=17117
Yes you can use Playerprefs but they aren't encrypted and can be modified unless you encrypt them with some script.
Your answer
![](https://koobas.hobune.stream/wayback/20220612053322im_/https://answers.unity.com/themes/thub/images/avi.jpg)