Question by
WilliamGLC · Apr 22, 2018 at 12:13 AM ·
playerprefssave data
Trouble with the Playerprefs
Hi there! So i'm having trouble with playerprefs. Basically, every time i close and turn it on again the game, when this void is called (from a button) it returns me -100 SCurrency and 1 SlowmoCounter.
Am I missing something here? because i've been with that for hours and no luck...
Thanks in advance!
public void PurchasePowerUpSlowmo () {
if (PlayerPrefs.GetInt ("SCurrency") >= SLOWMO_COST) {
GameController.S_CURRENCY = GameController.S_CURRENCY - SLOWMO_COST;
GameController.slowmoPuCounter = GameController.slowmoPuCounter + 1;
PlayerPrefs.SetInt ("SCurrency", GameController.S_CURRENCY);
PlayerPrefs.SetInt ("SlowmoCounter", GameController.slowmoPuCounter);
PlayerPrefs.Save ();
Debug.Log ("Tengo " + PlayerPrefs.GetInt ("SCurrency") + " de dinero");
Debug.Log ("Tengo " + PlayerPrefs.GetInt ("SlowmoCounter") + " PowerUp de Slowmo disponibles");
} else if (PlayerPrefs.GetInt ("SCurrency") < SLOWMO_COST || PlayerPrefs.GetInt ("SlowmoCounter") >= 5) {
Debug.LogError ("Not enough SCurrency or Max of PU achieved");
//Missatge en pantalla de que no tens dineros
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612161247im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
PlayerPrefs help ! 1 Answer
Saving In Between Scenes and Program Exit 0 Answers
Convert my playerpref back to obj 1 Answer
PlayerPrefs not saving specific values 1 Answer
How to reference data between scenes 1 Answer