Graphics Reference
In-Depth Information
// 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;
// rather than clutter up the start() func, we call Init to
// do any startup specifics
Init();
}
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;
}
public virtual void GameFinished()
{
DataManager.SetIsFinished(true);
}
public virtual void GameStart()
{
DataManager.SetIsFinished(false);
}
}
2.2.5.1 Script Breakdown
BasePlayerManager.cs derives from MonoBehavior so that it can use the system function
Awake() to call its Init() initialization:
public class BasePlayerManager : MonoBehavior
{
The Awake() function is based on the assumption that it may be reused, so it starts
out by setting the Boolean variable didInit to false. This variable can then be used to tell
whether or not the Init() function has been called and completed execution:
public virtual void Awake ()
{
didInit=false;
// rather than clutter up the start() func, we call Init to do any
// startup specifics
Init();
}
Search WWH ::




Custom Search