Graphics Reference
In-Depth Information
This player's data manager tracks health levels. myDataManager.ReduceHealth() takes
a single integer parameter of how much health should be reduced. In this game, the health
level is treated as lives, so it is called to take away one life here:
// reduce lives by one
myDataManager.ReduceHealth(1);
The game controller is called on to update the UI, either UpdateLivesP1() or
UpdateLivesP2(), depending on the ownerID for this player:
// update UI lives
if( ownerID==1 )
{
// as our ID is 1, we must be player 1
GameController_IP.Instance.UpdateLivesP1( myDataManager.GetHealth() );
} else {
// as our ID is 2, we must be player 2
GameController_IP.Instance.UpdateLivesP2( myDataManager.GetHealth() );
}
When this player's health level is less than 1, it is game over for this player:
if(myDataManager.GetHealth()<1) // <- game over
{
The player spaceship model is hidden by GameObject.SetActive():
// hide ship body
theMeshGO.SetActive(false);
The weapon needs to be disabled when the player is not active, which is the job of
the DisableCurrentWeapon() function on the weapon controller script (a reference to
Standard_SlotWeapon_Controller held in the variable weaponControl):
// disable and hide weapon
weaponControl.DisableCurrentWeapon();
The PlayerFinished() function is called now to close down this player:
// do anything we need to do at game finished
PlayerFinished();
} else {
Reaching the else of this condition means that the player just needs to be respawned
and that it has more than 1 life remaining. The player model is hidden with GameObject.
SetActive():
// hide ship body
theMeshGO.SetActive(false);
The weapon is disabled (it will be re-enabled when the player is respawned):
// disable and hide weapon
weaponControl.DisableCurrentWeapon();
Search WWH ::




Custom Search