Book Image

Creating E-Learning Games with Unity

By : David Horachek
Book Image

Creating E-Learning Games with Unity

By: David Horachek

Overview of this book

Table of Contents (17 chapters)
Creating E-Learning Games with Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Updating some systems


We introduce a new class, PlayerData, to track the current level and points accrued of the player. To make use of this new functionality, we need to update some systems by performing the following steps:

  1. Switch to the LEVEL1 scene. Double-click on the PlayerData script to begin editing it.

  2. Add a public int score and a public GameState level; note that in order to create an instance of the enumeration defined inside the GameMgr class, we need to prefix with GameMgr as shown in the following code:

    public class playerData : MonoBehaviour {
    public int score;
    public GameMgr eGameState;
  3. Add a public method called addScore(int dScore). This method will be used by the different systems (primarily MissionMgr), to add score to the player's record. Note that since we use an integer for score, we could use this same method to add score or penalize the player (by adding negative scores) as shown in the following code:

    public void AddScore(int dScore)
    {
      score += dScore;
    } 
  4. Add a public...