Review generated pause notice

from Unity coroutines
Unity 6.6 advanced 6 min 4 issues to find

Review this generated pause-notice component.

Show only the latest message for two seconds of real time, avoid duplicate timers, remain correct during pause, and leave no stale coroutine handle after disable.

csharp
using System.Collections;
using TMPro;
using UnityEngine;

public sealed class PauseNotice : MonoBehaviour
{
    [SerializeField] private GameObject panel;
    [SerializeField] private TMP_Text label;
    private bool isVisible;

    public void Show(string message)
    {
        label.text = message;
        panel.SetActive(true);
        isVisible = true;
        StartCoroutine(HideLater());
    }

    private IEnumerator HideLater()
    {
        yield return new WaitForSeconds(2f);
        panel.SetActive(false);
        isVisible = false;
    }
}

generated code is illustrative, not from any one model

Open in playground
Report an error