Code Framework

LevelManager Class

This page specifies each step in creating starter code framework for the LevelManager. Go to the bottom of this page to get the full Starter Code

Start by adding the following code to the top of the LevelManager Class

Updated 4/15/2020 1:00 pm

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour {

        ///CODE TO BE ADDED HERE

} //end class

Level-State Enums

The next code we'll add to the LevelManager class is a set of Enums that are used to track which state we are in. We'll create a LevelState variable: curLevel, and it's value will change as the Level changes. This corresponds to a simple Finite State Machine for managing levels.

Declare LevelManager Object Reference Variables

After declaring the LevelState enums, then we'll declare the LevelManager's object reference variables.

Start - Initialize Object References

Add the following code to the Start( ) method.

Check For Level End

Write code for the CheckLevelEnd method, this method will be executed every time the OnPlayerDataUpdate event occurs in GameData.

NextLevel - Finite State Machine Logic

This method manages the FSM control logic using switch-case structure. Each time this method is called, the matching logic must change the value of curLevel, and call a custom method: loadLevelX( ) where the details of the level loading logic are specified.

LoadLevel Methods

For each level change, a method: loadLevelX( )contains the level change logic. You'll need to add additional LoadLevel Methods for loadLevel3( ), etc.

Full Starter Code: Updated 4/15/2020

Last updated

Was this helpful?