Graphics Reference
In-Depth Information
// finally, tell the radar about the new player
theRadarControlScript.SetCenterObject( playerGO1.transform );
}
Invoked by the Start() function, the StartPlayer() function will tell the player when it
should begin the game. This function also grabs a reference to the player's data manager
and keeps it in a variable named mainPlayerDataManager1. This will be used by the game
controller later on for things like displaying the player's score in the UI:
void StartPlayer()
{
// grab a reference to the main player's data manager so we
// can update its values later on (scoring, lives etc.)
mainPlayerDataManager1=
playerGO1.GetComponent<BasePlayerManager>().DataManager;
Each player script incorporates a function called GameStart(), used to finalize what-
ever it needs to start the game:
// all ready to play, let's go!
thePlayerScript.GameStart();
}
The EnemyDestroyed() function is overridden from its original form in the
BaseGameController.cs script. It will be called whenever an enemy gets destroyed and will
be used to make an explosion effect, to update scoring, and to tell the wave spawner that
the player is one less enemy closer to completing the wave. Its parameters are the position
of the enemy when it was impacted, the enemy points value, and the ID of the projectile
it was hit by:
public override void EnemyDestroyed ( Vector3 aPosition,
int pointsValue, int hitByID )
{
The enemy explosion sound is the second item set in array via the Unity editor, mak-
ing its index number 1:
// tell our sound controller to play an explosion sound
BaseSoundController.Instance.PlaySoundByIndex( 1, aPosition );
Add the score to the main player's data manager:
// tell main data manager to add score
mainPlayerDataManager1.AddScore( pointsValue );
A call to update the UI is made via the function later in this script called
UpdateScoreP1(). To get at the player's score, the data manager provides the GetScore()
function:
// update the score on the UI
UpdateScoreP1( mainPlayerDataManager1.GetScore() );
// play an explosion effect at the enemy position
Explode ( aPosition );
Search WWH ::




Custom Search