获得当前时间的总毫秒数
程序员文章站
2022-06-21 10:37:34
...
代码
using System;
DateTime d = DateTime.Now;
TimeSpan ts = new TimeSpan(d.Ticks);
double startTime = ts.TotalMilliseconds; //获得当前时间的总毫秒数.
使用案例
void OnGUI(){
if (GUI.Button(new Rect(0,0,200,100),"find")) {
DateTime d = DateTime.Now;
TimeSpan ts = new TimeSpan(d.Ticks);
double startTime = ts.TotalMilliseconds; //获得当前时间的总毫秒数.
GameObject obj = GameObject.Find("GameObject (" + num +")");
num++;
d = DateTime.Now;
ts = new TimeSpan(d.Ticks);
double endTime = ts.TotalMilliseconds;
msg = "time(ms):" + (endTime - startTime) + " obj:" + obj.name;
}
if (GUI.Button (new Rect (0, 100, 300, 300), msg)) {
}
}
下一篇: 元素大小与获取各种高度 宽度 距离总结