Why does Unity Editor not reset playerpref values between tests?
Hi,
This one's got me scratching my head.
I am saving my users high score with the following code :-
if (thisScore > PlayerPrefs.GetInt(ScoreVariable))
{
PlayerPrefs.SetInt(ScoreVariable, thisScore);
}
However, as far as I know this value should reset between plays in the Unity editor, However Unity seems to store and recall them every runtime.
Having looked around for support on this, it seems that it is sth. to do with the way the data is written to and then stored in the registry (am on PC).
Any wisdom here would be greatly appreciated.
Thanks y'all.
Answer by ComradeVanti · Mar 19, 2016 at 01:57 PM
Playerprefs save variables between games.
When you test your game in the editor you are actually playing a nonbuild-version of your game.
Thus pressing play and stop will act just like if you were actually starting and closing your game --> PlayerPrefs will save the variables.
If you want to reset your PlayerPrefs just do: PlayerPrefs.DeleteKey ("nameOfTheVariable"); Just hook up this code to a button or something. :)
Good luck!
Answer by Kinkladze11 · Mar 19, 2016 at 02:04 PM
Ah.......got it, so my understanding was a bit wayward.
Thanks very much for the rapid response, really appreciated.
no problem :) Also: Dont add your comments as answers next time please :) If you click "Add comment" on answers you can, who guessed that, add comments without adding more answers :)
Oops....sorry.......don't come on here very often. Will be more more careful in future ;0