Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Dialog / DialogUIController.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. public class DialogUIController : MonoBehaviour
  6. {
  7. public TextMeshProUGUI textObject;
  8. float timer;
  9. public float maxTimer = 5;
  10. private bool txtTicked;
  11. // Start is called before the first frame update
  12. void Awake()
  13. {
  14. DialogController.dialogSkipped += DialogController_dialogSkipped;
  15. timer = maxTimer;
  16. }
  17. private void DialogController_dialogSkipped(DialogueMessage msg, DialogController controller)
  18. {
  19. if (textObject != null)
  20. {
  21. if (string.IsNullOrEmpty(msg.author))
  22. {
  23. textObject.text = msg.content;
  24. } else
  25. {
  26. textObject.text = $"{msg.author} : {msg.content}";
  27. }
  28. timer = maxTimer;
  29. txtTicked = true;
  30. }
  31. }
  32. // Update is called once per frame
  33. void Update()
  34. {
  35. if (timer <= 0)
  36. {
  37. timer = maxTimer;
  38. if (txtTicked)
  39. {
  40. txtTicked = false;
  41. textObject.text = string.Empty;
  42. }
  43. } else
  44. {
  45. timer -= Time.deltaTime;
  46. }
  47. }
  48. }