Recap: Achievement Popup
Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 14 of 50.
Challenge
EasyCoins lie around the yard, and the arrows walk the Player (Player.cs, ready). Give the game achievements that pop up on screen. Write three scripts; the scene already links their fields and wires the Achievements' On Unlocked (String) list to AchievementPopup.Show on the HUD.
Collector(on the Player) picks up every object taggedCoinit touches, removing it, and announces the new total with a public C# eventOnCoinsChangedthat passes an int. It knows nothing of achievements.Achievementslistens to itscollectorwhile it is active, and only then. At 1 coin it unlocksFirst Coin, at 3Pocket Moneyand at 6Coin Hoarder. Each unlock invokes its UnityEvent fieldonUnlocked, which passes the title (a string).AchievementPopup.Show(string title)showspanel, withtitleTextreadingUnlocked: First Coin, and hides itshowTime(2) seconds later. A Show while the panel is up shows the new title, and the 2 seconds start over.
Press Play, collect all six coins, then Check.
Try it yourself
using UnityEngine;
public class Achievements : MonoBehaviour
{
public Collector collector;
}
All lessons in Game Architecture in Unity
1Components, Not Hierarchies
Small ComponentsA Base Enemy ScriptAbstract ComponentsComponents Working TogetherRecap: Modular Turret10Project: Arena Survivor
The HeroEnemy Types3Events
C# Events in UnitySubscribe in OnEnableUnityEvent FieldsEvents Drive the UIRecap: Achievement Popup