想实现关于unity TextMeshPro打字机效果(即第一秒输出d,第二秒增加一个字符)。
上网查了下资料写出了如下代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;
using System.Threading;
public class spi : MonoBehaviour
{
public TMP_Text clockText;
// Start is called before the first frame update
string pr = "";
void DelayedLogic()
{
clockText.text = pr;
// 后续代码逻辑
}
void update_string(string a,int sz){
pr = a;
Invoke("DelayedLogic", 1f);
}
void Start(){
}
// void add(string a,int size){
// string tmp = "";
// for(int i = 0;i < size;i++){
// tmp+= a[i];
//
// }
// }
// Update is called once per frame
void Update()
{
//clockText.text = "1";
update_string("d",1); // 等待1秒后执行DelayedLogic函数
update_string("dd",1);
update_string("ddd",1);
}
}
结果,运行后直接输出了ddd。有没有大佬能解答下是哪里有问题?
顺便征求一份能实现打字机效果的代码。