- Home /
Question by
unity_f25emcU9mD-xFw · Aug 19, 2020 at 09:26 AM ·
playerprefsbuttonssavinglevelsunlock
PlayerPrefs not save my unlock button (Levels lock/unlock)
Hello, I have a problem adding buttons to prefab. I have several levels that are currently locked. The level buttons are locked with another button that on click open PopUp. In a PopUp is another button where on click unlock selected level (or sets the button to inactive). The problem is that Prefab doesn't save my button as inactive and every time I open it the "Locked Button" is active. Who can help me? Thanks everyone!
My code: public class UnlockLevel : MonoBehaviour {
public List<bool> unlocked;
public List<GameObject> LevelButton;
int i;
public void Unlock(int level)
{
LevelButton[i++].gameObject.SetActive(false);
PlayerPrefs.GetInt("Levels",i);
}
public void EnterLevel(int level)
{
if (unlocked[level] == true)
{
PlayerPrefs.SetInt("Levels", i);
}
}
}
Comment