Graphics Reference
In-Depth Information
2.2.2 Scene Manager
A manager script controls the game flow between physical scenes. Buttons from the menu
interface do not load scenes directly; it falls upon the scene manager script below to load them:
public class SceneManager : MonoBehavior
{
public string[] levelNames;
public int gameLevelNum;
public void Start ()
{
// keep this object alive
DontDestroyOnLoad (this.gameObject);
}
public void LoadLevel( string sceneName )
{
Application.LoadLevel( sceneName );
}
public void GoNextLevel()
{
// if our index goes over the total number of levels in the
// array, we reset it
if( gameLevelNum >= levelNames.Length )
gameLevelNum = 0;
// load the level (the array index starts at 0, but we start
// counting game levels at 1 for clarity's sake)
LoadLevel( gameLevelNum );
// increase our game level index counter
gameLevelNum++;
}
private void LoadLevel( int indexNum )
{
// load the game level
LoadLevel( levelNames[indexNum] );
}
public void ResetGame()
{
// reset the level index counter
gameLevelNum = 0;
}
}
2.2.2.1 Script Breakdown
Any script may call for a scene change, and menus, game controllers, or tutorial control-
lers may easily move between sections of the game without having to have filenames hard-
coded into them.
The level manager may also be a good place to call to show loading screens, implement
scene transitions (such as fade ins/outs or animations), or start downloading scenes from
a remote location.
Search WWH ::




Custom Search