Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

PlayerPrefs.SetBool and PlayerPrefs.GetBool

Discussion in 'Wish List' started by bigkahuna, Aug 19, 2008.

  1. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I wish these existed, not sure why they weren't included.
     
    Japheth_Hirpa and BonusB like this.
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It would be a bit more convenient, true, but it's simple enough to work around that using SetInt/GetInt:

    Code (csharp):
    1. var foo = true;
    2. // Save boolean using PlayerPrefs
    3. PlayerPrefs.SetInt("foo", foo?1:0);
    4. // Get boolean using PlayerPrefs
    5. foo = PlayerPrefs.GetInt("foo")==1?true:false;
    --Eric
     
    abelguima, aseaboyer and guetta18 like this.
  3. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,551
    You can shorten this:
    Code (csharp):
    1.  
    2. foo = PlayerPrefs.GetInt("foo")==1?true:false;
    3.  
    to this:
    Code (csharp):
    1.  
    2. foo = PlayerPrefs.GetInt("foo")==1;
    3.  
     
    juanitogan and guetta18 like this.