效果图:
public class TypewriterEffect : MonoBehaviour
{
private Text text;
public string content;
public float typeInterval = 0.1f;
private float currentTimne;
private int cutLength = 0;
void Awake()
{
text = GetComponent<Text>();
content = text.text;
}
void Update()
{
if (Time.time - currentTimne > typeInterval)
{
currentTimne = Time.time;
if (cutLength < content.Length)
{
cutLength++;
text.text = content.Substring(0, cutLength);
}
}
}