O'Reilly logo

Unity 5.x Game Development Blueprints by John P. Doran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. Then, add the following variables:
    public static GameController _instance;
    private int orbsCollected;
    private int orbsTotal;

    Note

    Although 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:
     GameObject[] orbs; orbs = GameObject.FindGameObjectsWithTag("Orb"); orbsCollected ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required