废话不多说上代码
using System.Collections;
using UnityEngine;
using TMPro;
public class DZJ : MonoBehaviour
{
public float delay = 0.1f; // 每个字符之间的延迟
public string fullText; // 要显示的完整文本
private string currentText = ""; // 当前显示的文本
void Start()
{
StartCoroutine(ShowText());
}
IEnumerator ShowText()
{
for (int i = 0; i < fullText.Length; i++)
{
currentText = fullText.Substring(0, i);
this.GetComponent<TMPro.TextMeshProUGUI>().text = currentText;
yield return new WaitForSeconds(delay);
}
}
}