using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace HC { public class HCToast : MonoBehaviour { private static HCToast instance; private void Awake() { if (instance != null) { Destroy(gameObject); } else { instance = this; } } private void Start() { instance.gameObject.SetActive(false); } public static HCToast Instance => instance; public Text toastText; private const float ToastDuration = 2f; public static void ShowToast(string message) { instance._ShowToast(message); } private void _ShowToast(string message) { instance.gameObject.SetActive(true); StartCoroutine(ShowAndHideToast(message)); } private IEnumerator ShowAndHideToast(string message) { toastText.text = message; instance.gameObject.SetActive(true); yield return new WaitForSeconds(ToastDuration); instance.gameObject.SetActive(false); } } }