Continue from where you left with PlayerPRefs

Hey guys, I have coin, level, health, hunger variable.I want to save them, I have a code something like that to save coin,

if(coin> PlayerPrefs.GetFloat("coin")){			
    PlayerPrefs.SetFloat("coin", coin);			
}
coin = PlayerPrefs.GetFloat("coin");

but when I buy something, it doesn’t decrease.


My hunger decreases by and by but when I exit the game, it starts with %100.

How can I fix them.Thanks in advance!

Anybody? Please guys help me :frowning:

Just like you are adding your variable “coin”, you also need to decrease it.

coin--; or coin -= 1;

Then you want to do

PlayerPrefs.SetFloat("coin", coin); // to save again

PlayerPrefs doesn’t know or care that coin has changed, it only knows what you tell it to save. Alternatively you can do like your code for adding is doing:

if(coin< PlayerPrefs.GetFloat("coin")){            // Notice the < sign
     PlayerPrefs.SetFloat("coin", coin);            
 }
 coin = PlayerPrefs.GetFloat("coin");