关于unity 打字机效果
  • 板块灌水区
  • 楼主Martlet
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/1/14 11:53
  • 上次更新2024/1/14 14:33:40
查看原帖
关于unity 打字机效果
543717
Martlet楼主2024/1/14 11:53

想实现关于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。有没有大佬能解答下是哪里有问题?

顺便征求一份能实现打字机效果的代码。

2024/1/14 11:53
加载中...