当前位置:网站首页>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);
边栏推荐
猜你喜欢
随机推荐
找两个单身狗
Selection of MOS tube
22-08-08 西安 尚医通(04)MongoDB命令、MongoTemplate、MongoRepository
学习一下 常说的节流
RNN-T
顺 序 表
【Word】Add subscripts to the text of Word at the same time
Distributed timing task framework xxl-job source code analysis
UI框架布局
command,shell,raw,script模块的作用和区别,file、copy、fetch、synchronize的应用
RT201 Domestic PA RF Power Amplifier Compatible with RFX2401C
matlab simulink球杆控制系统的模糊PID控制设计
筑牢安全“防火墙”河南通许县冯庄乡开展消防培训
机器人大赛总结
2022/08/08 学习笔记 (day25)File类
flask——介绍、安装、快速使用、配置文件、路由系统、视图
快速上手Shell,看这一篇就够了
地理空间分析库turf.js的学习
【计算机网络-哈工大】---学习笔记(下)---(二)Web安全威胁、SSL\IPsec、虚拟专用网、防火墙
通讯录改进即“保存”









