using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class PopupUI : MonoBehaviour { [SerializeField] private TextMeshProUGUI TextMessage; [SerializeField] private TextMeshProUGUI TextHighlight; [SerializeField] private string TextValue; [SerializeField] private int PopupsQueueDelay = 4; private List popups; private Animator animator; private AudioSource audioSource; private void Awake() { animator = GetComponent(); audioSource = GetComponent(); popups = new List(); } public void SetPopup(string text, bool setAsAlert = false) { popups.Add(new Popup { message = text, isAlert = setAsAlert }); if (popups.Count == 1) StartCoroutine(NextPopup()); } public IEnumerator NextPopup() { TextValue = popups[0].message; Debug.Log(TextValue); TextMessage.text = $"{TextValue}"; TextHighlight.text = $"{TextValue}"; animator.SetTrigger("PopupActivated"); if (popups[0].isAlert) { audioSource.enabled = true; } yield return new WaitForSeconds(PopupsQueueDelay); audioSource.enabled = false; popups.RemoveAt(0); if (popups.Count != 0) StartCoroutine(NextPopup()); } } struct Popup { public string message; public bool isAlert; }