Hi all,
I have a problem with saving the level progress in my game. After i closed the game (“Play” in unity) and open again all levels that i passed locked again. Im new with c# and unity engine i don"t understand why its not working.
This is the code:
public class LevelSelector : MonoBehaviour
{
public Button[] levelButtons; //--Levels
void Start()
{
int levelReached = PlayerPrefs.GetInt("levelReached", 1); //-- "1" = level 1 always opened
for(int i=0; i < levelButtons.Length; i++)
{
if(i+1 > levelReached)
{
levelButtons[i].interactable = false; //-- Disable the level button
}
}
}
}