PlayerPrefs in Unity with Boolean variable?

0

The PlayerPrefs It has something similar or it can even use boolean variable.

example:

PlayerPrefs.GetInt() // e para inteiros  
    
asked by anonymous 01.02.2016 / 16:44

2 answers

2

According to the documentation , it is only possible to save values of type float, int and string.

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);
    }
}
    
01.02.2016 / 17:02
0

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

link

And copy the script JS and paste in some folder in the project, to use with bool sim, same as playerPrefs, but there you only write

playerPrefsX.getBool or .setBool,

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

    
22.03.2016 / 21:57