So I'm trying to create a level system somewhat like in angry birds where after you complete one level next one is unlocked and so on.
So to get which all levels are unlocked I used playerPref.GetInt and a for loop to make these buttons interactable. But im getting an Index out of bound error for my **LevelsUnlocked **Loop I dont know why Totally unsure why it's happening, any ideas? (Probably something stupid because I'm a bit of a noob).
public class LevelManager : MonoBehaviour
{
int LevelUnlocked;
public Button[] Buttons;
void Start()
{
LevelUnlocked = PlayerPrefs.GetInt("LevelUnlocked", 1);
for(int i = 0; i < Buttons.Length; i++)
{
Buttons[i].interactable = false;
}
for (int i = 0; i < LevelUnlocked; i++)
{
Buttons[i].interactable = true;
}
}
}