在网上找了很多都没有涉及到这个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<TextMeshProUGUI>();
// TxtCurrentTime = GetComponent<TextMeshPro> ();
}
// Update is called once per frame
void Update()
{
//获取系统当前时间
System.DateTime NowTime = System.DateTime.Now.ToLocalTime();
Text.text = NowTime.ToString("HH:mm");
}
}