Book Image

Unity Game Development Blueprints

By : John P. Doran
Book Image

Unity Game Development Blueprints

By: John P. Doran

Overview of this book

Table of Contents (16 chapters)
Unity Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Keeping score


We now want to make it so that when we collect all of the orbs in the level, the goal will appear, and then you will win the game when you touch it:

  1. Go back into MonoDevelop, and select the GameController class. Once there, add the following variables:

    public static GameController _instance;
    private int orbsCollected;
    private int orbsTotal;

    Note

    While it may make more sense English-wise to use totalOrbs and collectedOrbs, programming-wise, putting the common word first means that when you start typing orbs, it will show both options for you when working with code completion in your own projects.

  2. As normal, we will need to set these variables as well in the Start function after the BuildLevel function call, otherwise the Orb objects will not exist:

    GameObject[] orbs;
    orbs = GameObject.FindGameObjectsWithTag("Orb");
    
    orbsCollected = 0;
    orbsTotal = orbs.Length;
  3. We will also want to initialize the _instance variable, but instead of using Start, we will use Awake, as follows:

    void Awake...