using UnityEngine;
using System.Collections;
using System;
public class TEST : MonoBehaviour {
//public float _angleSpeed;
string str = null;
float time;
float second;
float hour;
float minute;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//float eularY = Input.GetAxis("Mouse X") * _angleSpeed;
//transform.Rotate(new Vector3(0, eularY, 0));
time += Time.deltaTime;
if (time >= 1)
{
second++;
time -= 1;
}
if (second >= 60)
{
minute++;
second -= 60;
}
if (minute >= 60)
{
hour++;
minute -= 60;
}
str = string.Format("{0}时:{1}分:{2}秒", hour, minute, second);
//Vector3 c= Camera.main.WorldToScreenPoint(Input.mousePosition);
// Debug.Log(c);
}
void OnGUI()
{
//TimeSpan 是一个转换的方法比如下方 结果为00:02:00 From什么小括号里就是神魔然后往上转进制
//str = TimeSpan.FromSeconds(120).ToString();
//Debug.Log(str);
//OnGUI左上角为坐标原点 右下角为width height最大值
GUI.Label(new Rect(0 , 0,100,100), str);
}
}
OnGUI(用法)以及自制计时器
最新推荐文章于 2023-04-29 13:26:49 发布