- Home /
Question by
frankyboy450 · Aug 11, 2012 at 12:58 PM ·
changevalue
change playerpref number by one
hi. what do I have to do to add 1 to a playerpref value? I'm using it to count the number of deaths and save it for next time the player plays the game.
here's my code
function OnTriggerEnter (other : Collider)
{
if (other.CompareTag ("Enemy")) //if the player hit's the enemy
{
PlayerPrefs.SetInt("Player Deaths", 1); //set player deaths to +1
yield WaitForSeconds(0.05); // wait some time
Application.LoadLevel(Application.loadedLevel); //reset the scene
print (PlayerPrefs.GetInt("Player Deaths")); //print "Player Deaths"
}
I tried writing this:
PlayerPrefs.SetInt("Player Deaths", +=1);
but it just gave me an error
Assets/Scripts/Controlls.js(91,45): BCE0043: Unexpected token: +=.
Comment
Best Answer
Wiki
Answer by Bluk · Aug 11, 2012 at 01:06 PM
HI.
Try this:
PlayerPrefs.SetInt("Player Deaths", (PlayerPrefs.GetInt("Player Deaths")+1));
Your answer

Follow this Question
Related Questions
[Improvement] change image based on set value 1 Answer
Unity crashes when I change values on inspector 0 Answers
(C#) Return Float Variable to previous value 1 Answer
Change all value of variable 1 Answer
Prefab not changing variable's values 2 Answers