faster talk

This commit is contained in:
Xaver 2025-06-18 10:40:56 +02:00
parent 05380a3060
commit 5f50ca7f8e

View File

@ -1,29 +1,26 @@
using System.Collections; using System.Collections;
using UnityEngine;
using TMPro; using TMPro;
using UnityEngine.UI; using UnityEngine;
using UnityEngine.UIElements; using Event = AK.Wwise.Event;
public class DialogManager : MonoBehaviour public class DialogManager : MonoBehaviour
{ {
public GameObject dialogPanel; public GameObject dialogPanel;
public TextMeshProUGUI dialogText; // Use TextMeshProUGUI instead of Text public TextMeshProUGUI dialogText; // Use TextMeshProUGUI instead of Text
public PlayerMovement playerMovement; public PlayerMovement playerMovement;
[SerializeField] private AK.Wwise.Event TypeSound; [SerializeField] private Event TypeSound;
private Coroutine dialogCoroutine;
private void Start() private void Start()
{ {
dialogPanel.SetActive(false); // Hide on start dialogPanel.SetActive(false); // Hide on start
} }
Coroutine dialogCoroutine = null;
public void ShowDialog(string message) public void ShowDialog(string message)
{ {
print("should be showing dialog"); print("should be showing dialog");
if (dialogCoroutine != null) if (dialogCoroutine != null) StopCoroutine(dialogCoroutine);
{
StopCoroutine(dialogCoroutine);
}
dialogCoroutine = StartCoroutine(ShowDialogCoroutine(message)); dialogCoroutine = StartCoroutine(ShowDialogCoroutine(message));
dialogPanel.SetActive(true); dialogPanel.SetActive(true);
playerMovement.moveAllowed = false; playerMovement.moveAllowed = false;
@ -31,16 +28,16 @@ public class DialogManager : MonoBehaviour
// Coroutine to show dialog. Each letter is displayed one by one // Coroutine to show dialog. Each letter is displayed one by one
// 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 dialogText.text = ""; // Clear previous text
dialogPanel.SetActive(true); dialogPanel.SetActive(true);
playerMovement.moveAllowed = false; playerMovement.moveAllowed = false;
int letterCount = 0; var letterCount = 0;
int nextSoundTrigger = Random.Range(2, 5); // Random between 2 and 5 inclusive 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; dialogText.text += letter;
letterCount++; letterCount++;
@ -49,18 +46,16 @@ public class DialogManager : MonoBehaviour
{ {
TypeSound.Post(gameObject); TypeSound.Post(gameObject);
letterCount = 0; 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; dialogCoroutine = null;
} }
public void HideDialog() public void HideDialog()
{ {
dialogPanel.SetActive(false); dialogPanel.SetActive(false);