You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
|
|
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<Text>();
|
|
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();
|
|
|
|
}
|
|
|
|
}
|