- Home /
bool array to playerprefs
Hi All, I would like to save my boolean array to playerprefs not quite sure which is the best way to do it. I have a boolean array that is lvlcomplete[] and a level index "value" that is the current scene index. lvlcomplete[value] its then set to true once the level is completed with the minimum score required. So how would i then go about saving and retreiving the lvlcomplete[] boolean array in playprefs. Sorry for the total ignorance am a newbie.
Answer by OrcaAndo · Aug 09, 2018 at 03:45 AM
In this case, I use serializable and JsonUtility. But this is slow.
[System.Serializable]
class BoolArray { public List<bool> bools = new List<bool>(); };
void SaveBoolArray(string key, BoolArray boolArray)
{
var str = JsonUtility.ToJson(boolArray);
PlayerPrefs.SetString(key, str);
}
BoolArray LoadBoolArray(string key)
{
var str = PlayerPrefs.GetString(key);
return JsonUtility.FromJson<BoolArray>(str);
}
Your answer
Follow this Question
Related Questions
How to save an array to PlayerPrefs? 1 Answer
For In Loop Fills all values in arrays problem 2 Answers
Turn based games turn manager is spazzing out 2 Answers
Array Of Bools 4 Answers
PlayerPref/PlayerPrefsX why not able to store boolean values? 1 Answer