using System.Collections; using UnityEngine; using TMPro; using UnityEngine.UI; using UnityEngine.UIElements; public class DialogManager : MonoBehaviour { public GameObject dialogPanel; public TextMeshProUGUI dialogText; // Use TextMeshProUGUI instead of Text public PlayerMovement playerMovement; [SerializeField] private AK.Wwise.Event TypeSound; private void Start() { dialogPanel.SetActive(false); // Hide on start } Coroutine dialogCoroutine = null; public void ShowDialog(string message) { print("should be showing dialog"); if (dialogCoroutine != null) { StopCoroutine(dialogCoroutine); } dialogCoroutine = StartCoroutine(ShowDialogCoroutine(message)); dialogPanel.SetActive(true); playerMovement.moveAllowed = false; } // Coroutine to show dialog. Each letter is displayed one by one // Coroutine to show dialog. Each letter is displayed one by one IEnumerator ShowDialogCoroutine(string message) { dialogText.text = ""; // Clear previous text dialogPanel.SetActive(true); playerMovement.moveAllowed = false; int letterCount = 0; int nextSoundTrigger = Random.Range(2, 5); // Random between 2 and 5 inclusive foreach (char letter in message) { dialogText.text += letter; letterCount++; if (letterCount >= nextSoundTrigger) { TypeSound.Post(gameObject); letterCount = 0; nextSoundTrigger = Random.Range(2, 5); // Choose new interval } yield return new WaitForSeconds(0.05f); } dialogCoroutine = null; } public void HideDialog() { dialogPanel.SetActive(false); playerMovement.moveAllowed = true; } }