Gems on Screen
Part of the Building Real Games section of Coddy's Unity journey. Lesson 54 of 60.
Challenge
MediumCount the five gems as the player collects them.
- In
Player, addusing TMPro;and[SerializeField] private TMP_Text gemText;. - In
Start(), count the objects taggedGemand showGems: 0/5. - Add
public void AddGem(): one more gem, shown asGems: 1/5. - In
Gem, when aPlayerenters, call itsAddGem()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
10Project: 3D Platformer
The CourseMoving Platforms2Buttons and Screens
Buttons and onClickLambdasWiring in the InspectorPanels On and OffHealth BarsRecap: Upgrade Shop5Saving with PlayerPrefs
Save a NumberLoad with a DefaultHigh ScoreSave SettingsRecap: Coins in the Bank3The Game Manager
One Script Runs the GameThe SingletonGame StatesSwitching on the StateRecap: Round Manager6Project: Endless Runner
Three LanesObstacles Ahead9The New Input System
Two Input SystemsKeyboard and MousePressed This FrameInput ActionsRecap: Input SwapPractice on your own: Unity playground