Graphics Reference
In-Depth Information
// do play init things in this function
didInit= true;
}
public virtual void GameFinished()
{
DataManager.SetIsFinished(true);
}
public virtual void GameStart()
{
DataManager.SetIsFinished(false);
}
}
3.3.1 Script Breakdown
There is nothing particularly outstanding about the start of the script—the Awake() func-
tion calls Init() after setting the didInit Boolean to false:
public class BasePlayerManager : MonoBehavior
{
public bool didInit;
// the user manager and AI controllers are publically accessible so
// that our individual control scripts can access them easily
public BaseUserManager DataManager;
// note that we initialize on Awake in this class so that it is
// ready for other classes to access our details when they
// initialize on Start
public virtual void Awake ()
{
didInit=false;
Init();
}
The Init() function does a quick check to see whether there is already an instance of
BaseUserManager attached to the player gameObject using gameObject.GetComponent.
If its result is null, the script uses AddComponent to attach a new instance to it. Finally,
didInit is set to true:
public virtual void Init ()
{
// cache ref to our user manager
DataManager= gameObject.GetComponent<BaseUserManager>();
if(DataManager==null)
DataManager= gameObject.AddComponent<BaseUserManager>();
// do play init things in this function
didInit= true;
}
The GameFinished() and GameStart() functions are there to pass a message to the
user data manager. One good use for these might be a script that knows of the player's
Search WWH ::




Custom Search