Graphics Reference
In-Depth Information
{
LostLife();
}
}
void MakeInvulnerable()
{
isInvulnerable=true;
}
void MakeVulnerable()
{
isInvulnerable=false;
}
public void PlayerFinished()
{
// tell the player controller that we have finished
GameController_LBS.Instance.PlayerDied( id );
isFinished=true;
}
}
11.6.1 Script Breakdown
The player derives from BaseTopDown.cs, which was described back in Chapter 5. The
game-specific Player_LBS script adds weapon control, respawning, invulnerability, and a
data manager:
public class Player_LBS : BaseTopDown
{
Skipping down past the variable declarations, we can see that the Init() function
comes first. Notice that there is no Start() function attached to this script; expected behav-
ior might be to call the Init() function from Start(), but in this case the player's Init()
function will be called from the game controller so there is no need for a Start() function
in this class:
public override void Init ()
{
Calling base.Init() means that the Init() function in the base class (the one that this
script is derived from) will be called. It's a good way to keep all of the setup code from the
original function without having to duplicate or override it:
base.Init();
The game's god mode gives unlimited invulnerability to the player. It is provided
purely to make the game easier to test, as there is currently no way to activate this in-game
and it is assumed that the godMode checkbox should be set in the Inspector window of the
Unity editor on the component:
Search WWH ::




Custom Search