国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Unity-UGUI定時(shí)器(二)

2019-11-08 20:09:25
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
using UnityEngine;using System.Collections;using UnityEngine.UI;public class Timer : MonoBehaviour {    PRivate float allTime =0;    bool isPauseTime = false;    bool isStartTime = false;    public Text timerText;    private int hour;    private int minute;    private int second;    private float timeDelta;    void Start()    {        ShowTimerStr(allTime);    }    void Update()    {        if (!isPauseTime&&isStartTime)        {            allTime = Time.time-timeDelta;            ShowTimerStr(allTime);         }    }    //開(kāi)始計(jì)時(shí)    public void StartTimer()    {        timeDelta = Time.time;        isStartTime = true;        ContinueTimer();        }    //暫停計(jì)時(shí)    public void PauseTimer()    {        isPauseTime = true;        Time.timeScale = 0;    }    //繼續(xù)計(jì)時(shí)    public void ContinueTimer()    {        if(isStartTime)        {            isPauseTime = false;            Time.timeScale = 1;        }    }    //獲取小時(shí)    string GetHour(float time)    {        hour = (int)(time / 3600);        string timerStr;        if (hour < 10)            timerStr = "0" + hour.ToString()+":";        else            timerStr = hour.ToString() + ":";        return timerStr;    }    //獲取分鐘    string GetMinute(float time)    {        minute = (int)(time-hour*3600)/60;        string timerStr;        if (minute<10)            timerStr = "0" + minute.ToString() + ":";        else            timerStr = minute.ToString() + ":";        return timerStr;      }    //獲取秒    string GetSceond(float time)    {        second = (int)time-hour*3600-minute*60;        string timerStr;        if (second < 10)            timerStr = "0" + second.ToString() ;        else            timerStr = second.ToString() ;        return timerStr;      }    //顯示計(jì)時(shí)字符串    void ShowTimerStr(float time)    {        timerText.text = GetHour(time) + GetMinute(time) + GetSceond(time);    }}
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 轮台县| 黔南| 枞阳县| 许昌县| 北川| 沅陵县| 探索| 县级市| 寿光市| 柳州市| 新乐市| 漳平市| 遂溪县| 临汾市| 海宁市| 辉县市| 南乐县| 常山县| 莆田市| 遵义县| 恩施市| 张家港市| 安溪县| 淮阳县| 青河县| 黄梅县| 科技| 巴东县| 六枝特区| 含山县| 余庆县| 特克斯县| 通山县| 雅安市| 嘉义市| 白山市| 定襄县| 扶沟县| 宕昌县| 龙口市| 伊宁县|