- Home /
saving highscores
i've read many questions on this but can't seem to get mine to work, i have this script to save my score:
function saveScore(){
if(difficultyManager.difficulty == 1){
PlayerPrefs.SetFloat("EasyScore", spawner. waveCounter);
}
if(difficultyManager.difficulty == 2){
PlayerPrefs.SetFloat("MedScore", spawner.waveCounter);
}
if(difficultyManager.difficulty == 3){
PlayerPrefs.SetFloat("HardScore", spawner.waveCounter);
}
}
and this script to retrieve it:
var diff = 1;
var score = 0;
function Update () {
if(diff == 1){
score = PlayerPrefs.GetFloat("EasyScore");
}
if(diff == 2){
score = PlayerPrefs.GetFloat("EasyScore");
}
if(diff == 2){
score = PlayerPrefs.GetFloat("EasyScore");
}
GetComponent.<TextMesh>().text = ""+score;
}
but it simply doesn't work! also for when it does work, will it save and retrieve scores whilst in ther unity test play or does it only work on the build version, thanks in advance.
Answer by Seth-Bergman · Dec 28, 2012 at 10:14 PM
I hope your difficulty is set to 1, cuz that's all you are retrieving! otherwise this will definitely work.. if difficultyManager is set up like {easy,medium,hard} then easy is actually equal to zero, that MAY be the prob.. Just make sure you are saving to/retrieving the SAME thing!
And yes, it will work in the editor as well as an actual build.
can't believe that... i had done it a few different ways, without the stupid mistakes, but it didn't work, tried this way which should've worked, thats why i asked, tried it on medium and it didn't work... that's why! thank you for noticing what i failed too!
Your answer
Follow this Question
Related Questions
Having issues with PlayerPrefs... 2 Answers
PlayerPrefs 2 Answers
PlayerPrefs HighScore problems, it doesn't work. 4 Answers
Problem with High Score System using PlayerPrefs [C#] 1 Answer
Adding Value to Already Saved Values 1 Answer