diff --git a/blueberryPeak/Assets/Scripts/Player/DialogManager.cs b/blueberryPeak/Assets/Scripts/Player/DialogManager.cs index 142e1f4..5a72875 100644 --- a/blueberryPeak/Assets/Scripts/Player/DialogManager.cs +++ b/blueberryPeak/Assets/Scripts/Player/DialogManager.cs @@ -1,46 +1,43 @@ using System.Collections; -using UnityEngine; using TMPro; -using UnityEngine.UI; -using UnityEngine.UIElements; +using UnityEngine; +using Event = AK.Wwise.Event; public class DialogManager : MonoBehaviour { public GameObject dialogPanel; public TextMeshProUGUI dialogText; // Use TextMeshProUGUI instead of Text public PlayerMovement playerMovement; - [SerializeField] private AK.Wwise.Event TypeSound; + [SerializeField] private Event TypeSound; + + private Coroutine dialogCoroutine; 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); - } + 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) + private 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 + var letterCount = 0; + var nextSoundTrigger = Random.Range(3, 8); // Random between 2 and 5 inclusive - foreach (char letter in message) + foreach (var letter in message) { dialogText.text += letter; letterCount++; @@ -49,21 +46,19 @@ public class DialogManager : MonoBehaviour { TypeSound.Post(gameObject); letterCount = 0; - nextSoundTrigger = Random.Range(2, 5); // Choose new interval + nextSoundTrigger = Random.Range(3, 8); // Choose new interval } - yield return new WaitForSeconds(0.05f); + yield return new WaitForSeconds(0.02f); } dialogCoroutine = null; - } - public void HideDialog() { dialogPanel.SetActive(false); playerMovement.moveAllowed = true; } -} +} \ No newline at end of file