一、在场景中添加一个Text文本
二、创建一个脚本BaseDisplayInfo
三、将该脚本添加到场景的空物体上,然后将该Text文本拖拽到脚本的TxtCurrentTime位置
四、代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//Unity3D获取系统时间并且实时显示
public class BaseDisplayInfo : MonoBehaviour {
//系统当前时间
public Text TxtCurrentTime;
// Update is called once per frame
void Update ()
{
//获取系统当前时间
DateTime NowTime = DateTime.Now.ToLocalTime();
TxtCurrentTime.text = NowTime.ToString(“yyyy-MM-dd HH:mm:ss”);
}
}
本文介绍如何在Unity3D中使用C#脚本实时显示系统时间。具体步骤包括在场景中添加Text组件,创建并附加BaseDisplayInfo脚本到空物体上,通过Update方法每帧更新Text组件以显示当前系统时间。
2595

被折叠的 条评论
为什么被折叠?



