Graphics Reference
In-Depth Information
gameLevelNum is used to tell the scene manager which scene to load when using
the automated loading in GoNextLevel() or when LoadLevel() is called without a string
parameter. When a new game starts, gameLevelNum needs to be reset for the scene load-
ing to start at the beginning again:
public void ResetGame()
{
// reset the level index counter
gameLevelNum = 0;
}
At the end of a game level, calling GoNextLevel() will load the next scene automati-
cally and increment gameLevelNum:
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++;
}
LoadLevel() is used by the GoNextLevel() function to load a scene from the levelNames
array based on the index pass in as a parameter via indexNum:
private void LoadLevel( int indexNum )
{
// load the game level
LoadLevel( levelNames[indexNum] );
}
}
Search WWH ::




Custom Search