当前位置:网站首页>untiy 倒计时
untiy 倒计时
2022-08-09 05:41:00 【吴梓穆】
实现例如 01:30:50的倒计时
/// <summary>
/// 倒计时文本框
/// </summary>
private Text countDownText;
/// <summary>
/// 剩余的秒数
/// </summary>
private int secondsRemainng = 0;
private void OnDestroy()
{
//停止协程
StopAllCoroutines();
}
/// <summary>
/// 设置倒计时
/// </summary>
public void SetCountDown(int totalTime)
{
if (countDownText == null)
{
countDownText = transform.Find("TopPanel/CountDownText").GetComponent<Text>();
}
secondsRemainng = totalTime;
StartCoroutine(SetCountDownIE());
}
/// <summary>
/// 设置倒计时的协程
/// </summary>
private IEnumerator SetCountDownIE()
{
while (secondsRemainng > 0)
{
yield return new WaitForSeconds(1f);
secondsRemainng--;
//计算剩余时间
int hour, minute, second;
hour = secondsRemainng / 3600;
minute = (secondsRemainng % 3600)/60;
second = (secondsRemainng % 3600 % 60);
countDownText.text = hour.ToString("d2") + ":" + minute.ToString("d2") + ":" + second.ToString("d2");
}
//倒计时结束,结束考试
ExamControllerBase.Instance.FinishExam();
}
使用时调用方法SetCountDown();
例如
SetCountDown(3670);
边栏推荐
猜你喜欢
随机推荐
Chapter 3 Search and Graph Theory (1)
p67 mixin 混入/混合:两个组件共享一个配置
Why do enterprises need business intelligence BI in the digital age
shell regular expressions
Shell 文本三剑客 (grep、sed、awk)
#define
MySQL LIMIT + order by limit n,m 和 limit n的小坑
LDO和DC-DC的区别
Chapter7、基于图像的光照
pytorch实现GAN入门案例
Webgis地图框架的对比
Spark源码-任务提交流程-8-DAGScheduler任务切分
STM32之vl53l0x读取距离
二分搜索篇
Oracle01-安装与卸载
王爽 汇编语言个人疑问汇总第九篇
Still don't know what business intelligence (BI) is?After reading this article, you will understand
PWM输出模块PCA9685
Getting Started with MATLAB Image Processing
2022牛客多校联赛第七场 题解