Example #1
0
    public void LoadLevels()
    {
        for (int i = 0; i < levelHolder.transform.childCount; i++)
        {
            if (levelHolder.transform.GetChild(i).name.Contains("Level"))
            {
                Destroy(levelHolder.transform.GetChild(i).gameObject);
            }
        }

        UpdateProgress();

        Chapter currChap = chapters.Chapters[levelLoader.chapterIndex];

        int maxLevels = currChap.Levels.Length;

        if (unlockedChapter.val == currChap.Num && maxLevels > unlockedLevel.val)
        {
            maxLevels = unlockedLevel.val + 1;
        }

        for (int i = 0; i < currChap.Levels.Length; i++)
        {
            LevelObject temp = Instantiate(levelPrefab, levelHolder);
            temp.SetLevelNum(i);
            temp.SetLevelSelect(this);
            temp.SetData(i + 1, currChap.Levels[i].Description);
            if (i < maxLevels)
            {
                temp.SetEnabled(true);
            }
        }

        chapterDisplay.refreshText();
    }