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:
In
GameMgr.cs
, inside theChangeState()
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"));
Inside the
switch
statement thatChangeState()
implements, we signal aLoadLevelAdditive()
call when changing toLEVEL1
,LEVEL2
, orLEVEL3
. However, when switching toMAIN
, we simply need to destroy the_level1
,_level2
, and_level3
GameObjects since_global
remains persistent throughout.Recall that each level-specific scene file must be constructed according...