Graphics Reference
In-Depth Information
// do god mode, if needed)
if(!godMode)
{
MakeVulnerable();
} else {
MakeInvulnerable();
}
canControl will be used to determine whether or not the user can move this player
around via whichever input is attached:
// start out with no control from the player
canControl=false;
The standard slot weapon controller (as described in Chapter 6) is used by this player.
For this weapon controller to work correctly, its forceParent variable needs to be set to an
empty gameObject named GunMountPoint and the layer of that gameObject set to layer
number 9, the layer named “enemy projectile.” This will ensure that weapons are parented
to the right part of the player character and that the projectiles they fire may be identified
correct ly.
Expand out the player's gameObject in the Hierarchy window of the Unity editor and
you will see quite a lot of objects in it. As you get deeper into the hierarchy of gameObjects,
you will start to expand the bones of the skeleton used to animate the player. Deep down
under the object Bip 001 Right Hand is an empty gameObject named GunMountPoint.
The GunMountPoint is where weapons will be attached and it will move around with the
right hand, moving the weapon around as though the player character was holding it.
GunMountPoint gameObject is stored in the forceParent variable of the Standard_
SlotWeaponController component attached to the player (see Figure 11.4) and the
gameObject that will act as parent to all weapons in the game. By changing its layer, all
projectiles belong to that layer, too. This is how the game identifies which projectiles are
the player's and which are fired by the enemy.
The variable weaponControl will provide the reference we need to communicate with
it, as required:
// get a ref to the weapon controller
weaponControl= myGO.GetComponent<Standard_SlotWeaponController>();
As discussed in Chapter 3, the player manager script deals with all of the data associ-
ated with a player. Next in the script, if it does not already have a reference set up, myPlayer
Manager is set up with a reference to an instance of BasePlayerManager for health/damage
and scoring. We then set its name with SetName() and its health with SetHealth(). The
health value is used a little differently than you may think in that it is treated more as a
lives system than as health points. It is set to 3, and each time the player hits a projectile
it will be respawned and a single health unit taken away; when there is no health left the
game will end:
// if a player manager is not set in the editor, let's try
// to find one
if(myPlayerManager==null)
myPlayerManager= myGO.GetComponent<BasePlayerManager>();
Search WWH ::




Custom Search