Game Development Reference
In-Depth Information
level = lvl;
} ;
Now, let's connect the score tracking to the points in the game. Recall that
MissionMgr stores a points field for each mission once it is completed. Let's
go to MissionMgr and modify it to add the completed mission points to the
PlayerData component.
5. In MissionMgr , in the Validate() method, let's add a code block that
searches for the PlayerData component on the Player GameObject. If
it is found, then the points from the mission are added to the PlayerData
score as shown in the following code:
GameObject go =
GameObject.Find("Player1");
if (go)
{
PlayerData pd =
go.GetComponent<PlayerData>();
if (pd)
pd.AddScore(m.points);
}
6. In order to visualize the player's score, let's add a guiText script to the
bottom-right corner of the screen to show the score. To begin, create a new
guiText script.
7. Name this object score . Parent it to the _global GameObject (because it
should have persistency in the game). Set its position to ( 1 , 1 , 0 ) to offset the
coordinates of the pixel-offset to the upper-right corner of the screen. This
way, the negative x and y components of the pixel-offset will offset the score
from the corner by the specified amount. Set x to -60 and y to -20 .
Search WWH ::




Custom Search