好好学习

扫一扫关注

Unity3D使用C#脚本修改TextMeshPro的内容(以显示系统时间为例)

下载文本     郑连群2022-09-28 13:07:52 6560

在网上找了很多都没有涉及到这个TextMeshPro内容修改,踩了很多坑,记录一下
特别是using TMPro; public TextMeshProUGUI Text; GetComponent();

1、在Unity3D中创建一个TextMeshPro 2、在TextMeshPro下添加C# script 3、打开脚本
using System.Collections;using System.Collections.Generic;using UnityEngine;using TMPro;public class ShowTime : MonoBehaviour{    // Start is called before the first frame update    public TextMeshProUGUI Text;    // Start is called before the first frame update    void Start()    {      Text = transform.GetComponent();   // TxtCurrentTime = GetComponent ();    }    // Update is called once per frame    void Update()    {   //获取系统当前时间   System.DateTime NowTime = System.DateTime.Now.ToLocalTime();   Text.text = NowTime.ToString("HH:mm");    }}
 
反对 0举报 0 收藏 0 评论 0

(c)2022 haohaoxuexi.cc SYSTEM All Rights Reserved

冀ICP备17031443号-5