Graphics Reference
In-Depth Information
// the player is respawning
}
public virtual void StartGame()
{
// do start game functions
}
Other functions in BaseGameController are there to help turn games around quickly.
If there are things that you use in many different games, it may save time to include them
all in a script like this from which you can derive all other game controllers. It saves having
to rewrite the same code over and over again across multiple projects. One such example
is the Explode() function, which does just that:
public void Explode ( Vector3 aPosition )
{
// instantiate an explosion at the position passed into this
// function
Instantiate( explosionPrefab,aPosition, Quaternion.identity );
}
All Explode() does is instantiate a gameObject at a position passed in by the function
caller. Later versions of game controller scripts will use a separate spawn manager to deal
with instantiation, although at this stage, it is there simply to be as generic as possible by
not being reliant on any other scripts.
After Explode, we see two more of those empty functions, used to tell the game con-
troller when regular enemies are destroyed and when a boss is destroyed:
public virtual void EnemyDestroyed( Vector3 aPosition, int
pointsValue, int hitByID )
{
// deal with enemy destroyed
}
public virtual void BossDestroyed()
{
// deal with the end of a boss battle
}
All games will need some functions, such as a restart button and pause functions. In
their simplest form:
public virtual void RestartGameButtonPressed()
{
// deal with restart button (default behavior re-loads the
// currently loaded scene)
Application.LoadLevel(Application.loadedLevelName);
}
RestartGameButtonPressed() uses Unity's Application.LoadLevel function to reload
the current scene. Application.loadedLevelName returns a string referring to the name
of the scene the game currently has loaded in memory. You can also get an index number
Search WWH ::




Custom Search