Graphics Reference
In-Depth Information
The default values for the player manager's data manager are set up here:
// if a player manager is not set in the editor, let's try to find one
if(myPlayerManager==null)
myPlayerManager= myGO.GetComponent<BasePlayerManager>();
myDataManager= myPlayerManager.DataManager;
myDataManager.SetName("Player");
myDataManager.SetHealth(3);
The health system of the data manager is used, but instead of health points, it is used
as a store for the number of lives. ownerID is used again here to tell the game controller
which part of the UI (either player 1 or player 2) to update with this player's default num-
ber of lives:
// update UI lives
if(ownerID==1)
{
// if our owner ID is 1, we must be player 1
GameController_IP.Instance.UpdateLivesP1(myDataManager.GetHealth());
} else {
// we are player 2, so set that UI instead
GameController_IP.Instance.UpdateLivesP2(myDataManager.GetHealth());
}
Setting the isMouseControlled variable to true will add a new script component from
the script Mouse_Input.cs to be used as input for this player:
if(isMouseControlled)
{
// if we are going to use mouse controls, add a mouse input
// controller
mouse_input= gameObject.AddComponent<Mouse_Input>();
}
With Init() all done, the didInit Boolean variable is set to true. Other functions will
refer to this to check that the player has been set up successfully before trying to manipu-
late it in ways that might otherwise cause errors or problems:
didInit=true;
}
The Update() function is used for all of the main player updates. It overrides the
Update() function from the base class (BaseTopDownSpaceShip.cs):
public override void Update ()
{
Before doing anything to the player, such as updating its position or talking to the
weapon controller, the Init() function needs to have been called and completed. If it has,
Search WWH ::




Custom Search