Menu
CoddyTech

Recap: Popup Timer

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 17 of 64.

This chapter connected scripts with events: C# events for code that listens, UnityEvents for rows wired in the Inspector, and OnEnable with OnDisable to listen only while active.

challenge icon

Challenge

Easy

Make the achievement popup hide by itself.

  1. In AchievementPopup, add private float timeLeft; and set it to showTime in Show.
  2. In Update(), while timeLeft is above 0, take Time.deltaTime off it, and call panel.SetActive(false) when it runs out.

Press Play and grab a coin: the popup hides 2 seconds later. Then Check.

Try it yourself

using UnityEngine;
using TMPro;

// Shows an unlocked achievement's title on the HUD.
public class AchievementPopup : MonoBehaviour
{
    public GameObject panel;
    public TMP_Text titleText;
    public float showTime = 2f;

    public void Show(string title)
    {
        titleText.text = "Unlocked: " + title;
        panel.SetActive(true);
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Game Architecture in Unity

Practice on your own: Unity playground