Question by
UDN_b7e02a1f-c47d-43ec-877f-367ff4696609 · Mar 26, 2018 at 03:27 PM ·
androidbuildplayerprefsloadingsaving
Playerprefs don't work on Android
Hello, I have a problem. My playerprefs don't load/save on Android, I can't figure out where is the problem. This same code works on iOS and even on PC, can you help me please? Thanks, any help is appreciated.
public bool[] completedLevels;
void Start()
{
for (int i = 0; i < completedLevels.Length; i++)
{
if (PlayerPrefs.GetInt(i.ToString(), 0) == 1)
{
completedLevels[i] = true;
} else
{
completedLevels[i] = false;
}
}
}
void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
{
saveCompletedLevels();
}
}
void OnApplicationQuit()
{
saveCompletedLevels();
}
void OnApplicationFocus(bool focusStatus)
{
if (focusStatus)
{
saveCompletedLevels();
}
}
public void saveCompletedLevels()
{
for (int i = 0; i < completedLevels.Length; i++)
{
if (completedLevels[i] == true)
{
PlayerPrefs.SetInt(i.ToString(), 1);
}
else
{
PlayerPrefs.SetInt(i.ToString(), 0);
}
}
PlayerPrefs.Save();
}
Comment
Your answer
Follow this Question
Related Questions
How to allow coins to increase its Player.Prefs file and save, but then load it again next time. 1 Answer
Saving a Player Pref Exclusive to that instance of a script 0 Answers
PlayerPrefs working on PC but not on Android. [2020] 0 Answers
PlayerPrefs help ! 1 Answer
Monetization breaks iOS build in XCode. Also breaks Android build. 1 Answer