I feel like I am missing something simple… but basically I have a menu where the player picks level 1-36. Each button is names after the level it loads… 1 is 1, 13 is 13…
I setup player prefs to store a variable when loading levels…
Load level 5, if playerpref of UnlockedLevel<5, set to 5…
That bit works… even hitting delete and setting it back to 1 works (according to some debug outputs).
Now when the menu loads I believe I should be able to loop through from 1 to n where n is playerprefs UnlockedLevel value.
void LoadMainMenu()
{
Button levelButton;
Application.LoadLevel("Main");
//unlock Levels from Player Prefs
int UnlockToLevel = PlayerPrefs.GetInt ("UnlockToLevel");
for(int n = 1; n <= UnlockToLevel; n++)
{
levelButton = GameObject.FindGameObjectsWithTag (n.ToString ());
levelButton.SetActive(true);
}
I know UnlockToLevel is being set to the proper number.
This is my first attempt at a for loop, but I believe the loop itself is correct.
I am sure my issue is saying “let’s grab button n”.
I tried it with “3” instead of n and the error for that line disappears but button 3 isn’t being unlocked.
So should I somehow cast the int to a string?
Am I even going about this the right way?
Thanks!
EDIT: updated code to show what I have changed to. I think i’m getting closer…