Menu
CoddyTech

Recap: Achievement Popup

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 14 of 50.

challenge icon

Challenge

Easy

Coins 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 tagged Coin it touches, removing it, and announces the new total with a public C# event OnCoinsChanged that passes an int. It knows nothing of achievements.
  • Achievements listens to its collector while it is active, and only then. At 1 coin it unlocks First Coin, at 3 Pocket Money and at 6 Coin Hoarder. Each unlock invokes its UnityEvent field onUnlocked, which passes the title (a string).
  • AchievementPopup.Show(string title) shows panel, with titleText reading Unlocked: First Coin, and hides it showTime (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