Graphics Reference
In-Depth Information
gameObject and wants to tell about the state of the game. Rather than having to use a call
to GetComponent to find this script, it may use gameObject.SendMessage to call a func-
tion instead. This would be slightly more efficient than having to use GetComponent and
access the function directly:
public virtual void GameFinished()
{
DataManager.SetIsFinished(true);
}
public virtual void GameStart()
{
DataManager.SetIsFinished(false);
}
}
3.4 User Data Manager (Dealing with Player Stats
Such as Health, Lives, etc.)
It is not uncommon to store player information in a game controller or similar script
removed from individual player objects. This approach may be well suited to single-player
games, but moving to games that have more than one player may prove to be problematic.
One solution may be for the game controller to have an array of classes containing player
stats, manipulating them when other functions tell it to; but why not attach the player stats
to each player and make it self-sufficient?
he framework for this topic uses a data manager class for each player, consisting of
everything we need to store for a single player:
1. Score
2. High score
3. Level
4. Health
5. Whether or not the player is finished (no longer active)
6. Name of the player
Each player has the BaseUserManager.cs script attached to its gameObject, giving
each player its own set of stats. The game controller or other script elsewhere in the game
structure can easily search for and access a player's information.
The user manager script looks like this:
public class BaseUserManager : MonoBehavior
{
// gameplay specific data
// we keep these private and provide methods to modify them
// instead, just to prevent any accidental corruption or invalid
// data coming in
Search WWH ::




Custom Search