Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Subtracting a PlayerPref Instead of Setting It

Discussion in 'Scripting' started by byro210, Jun 12, 2014.

  1. byro210

    byro210

    Joined:
    Feb 18, 2014
    Posts:
    121
    How can I subtract a PlayerPref instead of setting it so I want
    PlayerPrefs.GetInt("Player Style"); to Subtract 5 instead of doing
    PlayerPrefs.SetInt("Player Style", 5); since it wont always equal 5

    Help would be much appreciated o_O
     
  2. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    Code (csharp):
    1. int playerStyle = PlayerPrefs.GetInt("Player Style");
    2. PlayerPrefs.SetInt("Player Style", playerStyle - 5);
     
    LuigiBestCRT likes this.
  3. toreau

    toreau

    Joined:
    Feb 8, 2014
    Posts:
    204
    Or in just one line:

    Code (CSharp):
    1. PlayerPrefs.SetInt( "Player Style", PlayerPrefs.GetInt("Player Style") - 5 );
     
  4. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
  5. amoraleite

    amoraleite

    Joined:
    Oct 16, 2014
    Posts:
    41
    Thank you guys!