国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 乌拉特前旗| 澄城县| 磴口县| 固原市| 福海县| 酒泉市| 修文县| 高安市| 客服| 伊金霍洛旗| 同心县| 运城市| 永安市| 莲花县| 南昌县| 弋阳县| 庆云县| 五莲县| 福州市| 登封市| 铜山县| 怀化市| 滁州市| 莱州市| 开远市| 旌德县| 博乐市| 盘锦市| 任丘市| 彭泽县| 潜山县| 呼伦贝尔市| 云浮市| 电白县| 新兴县| 秀山| 枝江市| 灵武市| 五常市| 汉寿县| 德化县|