Menu
CoddyTech

Gems on Screen

Part of the Building Real Games section of Coddy's Unity journey. Lesson 54 of 60.

challenge icon

Challenge

Medium

Count the five gems as the player collects them.

  1. In Player, add using TMPro; and [SerializeField] private TMP_Text gemText;.
  2. In Start(), count the objects tagged Gem and show Gems: 0/5.
  3. Add public void AddGem(): one more gem, shown as Gems: 1/5.
  4. In Gem, when a Player enters, call its AddGem() and destroy the gem.

Press Play and collect gems. Then Check.

Try it yourself

using UnityEngine;

public class Gem : MonoBehaviour
{
    // A later lesson fills this in: a gem to collect.
}

All lessons in Building Real Games

Practice on your own: Unity playground