using UnityEngine; using UnityEngine.UI; using DG.Tweening; using System; using System.Collections; public class TextWrite : MonoBehaviour { private Text _text; [SerializeField] float speed=0.15f; private void Start() { _text = GetComponent(); string str = _text.text; _text.text = ""; _text.DOText(str, str.Length * speed, false); } public void ChangeText(string str) { _text.DOText("",0.01f); _text.DOText(str, str.Length * speed, true); } public void ChangeText(string str,Action action) { _text.DOText("", 0.01f); _text.DOText(str, str.Length * speed, true); float time = str.Length * speed; Debug.Log(time); StartTimeAction( time, action); } public void StartTimeAction(float time, Action action) { StartCoroutine(TimeAction(time, action)); } IEnumerator TimeAction(float time, Action action) { yield return new WaitForSeconds(time); action.Invoke(); } }