- Home /
Question by
ShinyTaco · Dec 19, 2013 at 06:32 AM ·
playerprefssaveadd
Why is PlayerPrefs Not Saving?
Hi guys,
Really stupid question, but I can't figure out why PlayerPrefs isn't saving?
var total:int=0;
var one:int=1;
function Awake () {
PlayerPrefs.SetInt("total", one);
PlayerPrefs.Save();
print(zero);
}
Shouldn't this be adding +1 to total every time the script is called?
What am I doing wrong here?
Thanks.
Comment
Best Answer
Answer by ByteSheep · Dec 19, 2013 at 07:28 AM
You aren't using the total variable, if you want to add one to the total variable and then save the change it would have to look something like this:
var total:int=0;
var one:int=1;
function Awake ()
{
total = PlayerPrefs.GetInt("saved_total"); //set the total variable to the previously saved value
total += one; //add one to total
PlayerPrefs.SetInt("saved_total", total); //set the new total value
PlayerPrefs.Save();
}
I see, and it's clear now.
Thank you very much for your explanation and time.
Your answer
![](https://koobas.hobune.stream/wayback/20220613124452im_/https://answers.unity.com/themes/thub/images/avi.jpg)