O'Reilly logo

Creating E-Learning Games with Unity by David Horachek

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required