- Home /
increase playerprefs
I would like to increase a player prefs to save the number of items dropped.
The enemy once killed releases the item and when there is a collision with the player I put:
void OnCollisionEnter ()
{
Destroy (gameObject);
provadrop = PlayerPrefs.GetInt("drop1") + 1;
PlayerPrefs.SetInt("drop1", provadrop);
}
The value is always zero
In another script, instead I put
PlayerPrefs.SetInt ("drop1", 0);
I use a similar setup as yours and it works fine for me. Are you sure you have the drop1 written properly?
In another script, ins$$anonymous$$d I put PlayerPrefs.SetInt ("drop1", 0);
Can you describe that script? That will reset it to 0, if it is in a script that is called often or between the SetInt method it will set the int to 0. Also are you Saving your PlayerPrefs?
@Landern I have change the script whit
void OnCollisionEnter () { Destroy (gameObject); provadrop = PlayerPrefs.GetInt("drop1") + 1; PlayerPrefs.SetInt("drop1", provadrop); PlayerPrefs.Save (); }
and cancelled the
PlayerPrefs.SetInt ("drop1", 0);
in the other script
Answer by koray1396 · Jun 23, 2014 at 03:56 PM
You can not run the script after destroying the gameObject.
void OnCollisionEnter ()
{
provadrop = PlayerPrefs.GetInt("drop1") + 1;
PlayerPrefs.SetInt("drop1", provadrop);
Destroy (gameObject);
}
Lol , what a stupid thing I did, however, thank you very much!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How To Add PlayerPrefs Scores? 1 Answer
Saving final score and displaying on main menu 1 Answer
What am I doing wrong with PlayerPrefs? 3 Answers
How Do You Have Multiple High Scores For 1 GameOverScene? 1 Answer