Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

Issues creating proper level-unlocking script

$
0
0
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?

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>