Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Dialog / DialogUIController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class DialogUIController : MonoBehaviour
{
    public TextMeshProUGUI textObject;

    float timer;
    public float maxTimer = 5;
    private bool txtTicked;
    // Start is called before the first frame update
    void Awake()
    {
        DialogController.dialogSkipped += DialogController_dialogSkipped;
        timer = maxTimer;
    }

    private void DialogController_dialogSkipped(DialogueMessage msg, DialogController controller)
    {
        if (textObject != null)
        {
            if (string.IsNullOrEmpty(msg.author))
            {
                textObject.text = msg.content;
            } else
            {
                textObject.text = $"{msg.author} : {msg.content}";
            }
            timer = maxTimer;
            txtTicked = true;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (timer <= 0)
        {
            timer = maxTimer;
            if (txtTicked)
            {
                txtTicked = false;
                textObject.text = string.Empty;
            }
        } else
        {
            timer -= Time.deltaTime;
        }
    }
}