- Home /
Issues creating proper level-unlocking script
I'm creating a level unlocking script based on the MenuLevelLock script used in James Arndt's YT tutorial series. I've already converted his base MenuLevelLock from Javascript to C#; however, I'm trying to make the script more user-friendly within the Unity editor by creating arrays for all the public variables he set up before. Here are all of the public arrays I've set up (w/ comments included):
public GUITexture[] levelsUnlocked; //for displaying icons for unlocked levels
public GUITexture[] levelsLocked; //for displaying icons for locked levels
public GameObject[] levelColliders; //for selecting unlocked levels w/ mouse
public int[] levelsComplete; //PlayerPref values for deciding which levels have been complete
public string[] levelKeys; //PlayerPref keys for deciding which levels are unlocked
With the below function, I'm trying to set the levels active or inactive based on their levelsComplete value:
void SetLockedAndUnlockedLevels() {
foreach (int levComplete in levelsComplete)
{
foreach (GameObject levCollider in levelColliders)
{
if (levComplete != 0)
{
levCollider.SetActive(true);
}
else
{
levCollider.SetActive(false);
}
}
foreach (GUITexture levUnlocked in levelsUnlocked)
{
if (levComplete != 0)
levUnlocked.enabled = true;
else
levUnlocked.enabled = false;
}
foreach (GUITexture levLocked in levelsLocked)
{
if (levComplete != 0)
levLocked.enabled = false;
else
levLocked.enabled = true;
}
}
}
Unfortunately, every time I run this code, Unity locks up forcing me to quit the program.
Given the above code, what am I doing wrong that's making Unity to lock up?
Does anyone have a suggestion yet? I'm still stuck on it. If I've been too vague with something, please let me know.
Your answer
Follow this Question
Related Questions
Problems with PlayerPrefs or something else 1 Answer
Function executes only on 1 object 1 Answer
Trying to save/load from PlayerPrefs to Array and vice-versa 1 Answer
Get child position from last gameobject in array 2 Answers
Array problems 3 Answers