x


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: +=.
more ▼

asked Aug 11 '12 at 12:58 PM

frankyboy450 gravatar image

frankyboy450
61 6 10 17

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

HI.

Try this:

PlayerPrefs.SetInt("Player Deaths", (PlayerPrefs.GetInt("Player Deaths")+1));
more ▼

answered Aug 11 '12 at 01:06 PM

Bluk gravatar image

Bluk
301 1 3 4

It works :D Awesome! Thank you so much!

Aug 11 '12 at 05:53 PM frankyboy450
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x380
x123

asked: Aug 11 '12 at 12:58 PM

Seen: 241 times

Last Updated: Aug 11 '12 at 05:53 PM