- Home /
problem incrementing player prefs
in my game i want the player taking screenshots of the game. Am using playerprefs to save number of screenshots so i can have screen-1,screen-2 screen-3 etc the problem is it does not increment above 1 and i don't know why here is my code
function Awake() {
if(!PlayerPrefs.HasKey("HighScore")){
PlayerPrefs.SetInt("HighScore",0);
}
}
function Encode{
Application.CaptureScreenshot( System.IO.Path.Combine(
System.Environment.GetFolderPath( System.Environment.SpecialFolder.MyPictures ),
"screen-" + PlayerPrefs.GetInt("HighScore") + ".png") );
yield WaitForSeconds(2);
PlayerPrefs.SetInt("HighScore",(PlayerPrefs.GetInt("Highscore")+1 ));
}
thanks for any help
Answer by billykater · Dec 09, 2013 at 03:20 PM
You are using "HighScore" and "Highscore". This is most likely the cause of your problem.
Answer by Statement · Dec 09, 2013 at 03:21 PM
PlayerPrefs.SetInt("HighScore", ...)
PlayerPrefs.GetInt("Highscore")
See the error? The keys are not the same. One has a capital S, one does not.
i know am not supposed to ask another question here but would you $$anonymous$$d if i did?
If it's a different question, ask a new question. It doesn't take long. Also search of someone already asked your question and if someone already answered that question, to avoid duplicate questions.