using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class WriteDialogue : MonoBehaviour{
    public TextMeshProUGUI TextDialogue;
    public float delayWrite = 0.05f;
    public string text;
    public void Speak(){
        StartCoroutine("WriteText", TextDialogue.text);
    }
    public void StopSpeak(){
        StopCoroutine("WriteText");
    }
    IEnumerator WriteText(string dialogue){
        if(TextDialogue.text != ""){
            text = TextDialogue.text;
            TextDialogue.text = "";
        }
        for(int letter = 0; letter < dialogue.Length; letter++){
            TextDialogue.text = TextDialogue.text + dialogue[letter];
            yield return new WaitForSeconds(delayWrite);
        }
    }
}