Graphics Reference
In-Depth Information
The first player object added to the list of players in the Unity editor Inspector win-
dow needs to be the main player, in gaming terms we might call this “player one”. When
players are generated, the SpawnController stores their objects in an array so they can
be accessed later on, from other scripts. Access to the array is provided by the function
GetPlayerGO(index number). Here, we call upon the SpawnController to return the main
player object to be stored in playerGO1:
// grab a ref to the player's gameobject for later
playerGO1 = SpawnController.Instance.GetPlayerGO( 0 );
GetComponent() is used to grab a reference to the main player's control script, which
is stored in the variable named thePlayerScript:
// grab a reference to the focussed player's controller script, so
// that we can do things like access its speed variable
// thePlayerScript = ( Player_LBS ) playerGO1.GetComponent<Player_
LBS>();
The next line assigns an ID number to the player, used later to identify the origin of
projectiles:
// assign this player the id of 0
thePlayerScript.SetID( 0 );
To allow control of the main player by the user, SetUserInput is called. We also keep a
reference to this player script in the variable named focusPlayerScript, since it is the player
that the game controller will be focused on when providing data to the UI and the player
that the camera needs to focus on, too:
// set player control
thePlayerScript.SetUserInput( true );
// as this is the user, we want to focus on this for UI etc.
focusPlayerScript = thePlayerScript;
The script looks for a reference to a gameObject named CamTarget attached to the
main player. If it exists, it will be used as a target for the camera. If not, the player is set to
be the camera target instead:
// see if we have a camera target object to look at
Transform aTarget= playerGO1.transform.FindChild("CamTarget");
if(aTarget!=null)
{
// if we have a camera target to aim for, instead of
// the main player, we use that instead
Camera.main.SendMessage("SetTarget", aTarget );
} else {
// tell the camera script to target the player
Camera.main.SendMessage("SetTarget",
playerGO1.transform );
}
The radar system needs to know which object to center on. A quick call to its
SetCenterObject() function is made, with the parameter being the player's transform:
Search WWH ::




Custom Search