Playerprefs in Unity with Boolean variable?

Asked

Viewed 241 times

0

The PlayerPrefs Has something similar or it itself can use boolean variable.

example:

PlayerPrefs.GetInt() // e para inteiros  

2 answers

2


According to the documentation, only float, int and string values can be saved.

Since it is not possible to store booleans, you can store 0 or 1 and convert them, see the example below:

using UnityEngine;
using System.Collections;

public static class CustomPlayerPref
{
    public static bool GetBool (string key)
    {  
        return PlayerPrefs.GetInt(key) == 1;
    }

    public static void SetBool (string key, bool state)
    {
        PlayerPrefs.SetInt (key, state ? 1 : 0);
    }
}

0

Unity native guy does not, but if you access this link

http://wiki.unity3d.com/index.php?title=PlayerPrefsx

And copy the JS script and paste in some folder in the project, da para usar com bool sim, igual o playerPrefs, but then you only write

playerPrefsX.getBool or . setBool,

At the time I found one that saved up to Colors, but not found now to post here hahaha, I hope it helps !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.