一、实现目标:在游戏UI上显示系统时间
二、实现方法01:Canvas-TMP(TextMeshPro)方法:
The First Step:创建Tmp -- SystemTimerText01
The Second Step:创建C#脚本 -- SystemTimer
TheThird Step:编辑脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using TMPro;
public class SystemTimer : MonoBehaviour
{
public TextMeshProUGUI SystemTimerText01;
//保存当前时间
public DateTime CurrentTime;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//获取当前时间
CurrentTime = DateTime.Now.ToLocalTime();
//将所需时间格式赋给 SystemTimerText01.text
SystemTimerText01.text = CurrentTime.Year+"/"+CurrentTime.Month+"/"
+CurrentTime.Day+"("+CurrentTime.Hour+":"+
CurrentTime.Minute+":"+CurrentTime.Second+")";
}
}
三、结果测试
四、结果分析
目前无法显示中文: