Unity 倒计时
Posted 格拉格拉
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity 倒计时相关的知识,希望对你有一定的参考价值。
public int curTime = 0;
------------------------------------------------------------------------------------------------------
TimeSpan st = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0);
long aTime = Convert.ToInt64(st.TotalSeconds);
if (PlayerPrefs.GetInt("AdTime", 0) != 0)
{
curTime = 900 - (int)(aTime - (PlayerPrefs.GetInt("AdTime", 0)));
if (curTime > 0)
{
StartCoroutine("TimeLine");
}
}
------------------------------------------------------------------------------------------------------
IEnumerator TimeLine()
{
yield return new WaitForSeconds(1f);
curTime -= 1;
if (curTime > 0)
{
StartCoroutine("TimeLine");
}
}
----------------------------------------------------------------------------------------------------------
if (curTime > 0) {
_hour = (curTime/3600).ToString();
if ((curTime / 3600) < 10) {
_hour = "0"+_hour;
}
_min = (curTime % 3600 /60).ToString();
if ((curTime % 3600 /60) < 10)
{
_min = "0" + _min;
}
_seconds = (curTime % 3600 % 60).ToString();
if ((curTime % 3600 % 60) < 10)
{
_seconds = "0" + _seconds;
}
newUserPackage.text = string.Format("限时 {0}:{1}:{2}", _hour, _min, _seconds);
}
以上是关于Unity 倒计时的主要内容,如果未能解决你的问题,请参考以下文章
Unity3D日常开发Unity3D中实现计时器工具类-正计时倒计时暂停计时加速计时
Unity3D日常开发Unity3D中实现计时器工具类-正计时倒计时暂停计时加速计时