Graphics Reference
In-Depth Information
Init() starts out by looking to find a reference to a DataManager script component
(BaseUserManager as explained earlier in this chapter). gameObject.GetComponent()
will return a reference to BaseUserManager if it has been added to the gameObject that
this script is attached to:
public virtual void Init ()
{
// cache ref to our user manager
DataManager= gameObject.GetComponent<BaseUserManager>();
At this point, if the DataManager variable is null, we know that the component has not
been added to this gameObject, and this code goes on to use gameObject.AddComponent()
to add a BaseUserManager component through the code
if(DataManager==null)
DataManager= gameObject.AddComponent<BaseUserManager>();
Now that the Init() function is done, didInit can be set to true:
// do play init things in this function
didInit= true;
}
GameFinished() will be called from an outside script (possibly the game controller script
or similar game-state management script) to tell this player when the game is over:
public virtual void GameFinished()
{
DataManager.SetIsFinished(true);
}
Just like GameFinished(), GameStart() will be called from an outside script when it
is time to start the game. DataManager.SetIsFinished() is called to set the isFinished vari-
able of this player's data manager to false:
public virtual void GameStart()
{
DataManager.SetIsFinished(false);
}
}
2.2.6 BaseInputController.cs
The input controllers provide input for use by the player controller. The BaseInputController.
cs looks like this:
public class BaseInputController : MonoBehavior
{
// directional buttons
public bool Up;
public bool Down;
public bool Left;
public bool Right;
Search WWH ::




Custom Search