Book Image

Creating E-Learning Games with Unity

By : David Horachek
Book Image

Creating E-Learning Games with Unity

By: David Horachek

Overview of this book

Table of Contents (17 chapters)
Creating E-Learning Games with Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using delete/load patterns


Having planned how to organize our GameObjects into globally persistent and level-specific lifespans, we must further update GameMgr.cs to ensure that only the current level is loaded at any time. To do this, perform the following steps:

  1. In GameMgr.cs, inside the ChangeState() method, the first thing we do is tell the game to delete any potential level-specific GameObject hierarchies that may be loaded:

    if (GameObject.Find("_level1")
      Destroy (GameObject.Find ("_level1"));
    if (GameObject.Find("_level2")
      Destroy (GameObject.Find ("_level2"));
    if (GameObject.Find("_level3")
      Destroy (GameObject.Find ("_level3"));
  2. Inside the switch statement that ChangeState() implements, we signal a LoadLevelAdditive() call when changing to LEVEL1, LEVEL2, or LEVEL3. However, when switching to MAIN, we simply need to destroy the _level1, _level2, and _level3 GameObjects since _global remains persistent throughout.

  3. Recall that each level-specific scene file must be constructed according...