当前位置:网站首页>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);
边栏推荐
- IDEA05:线程管理
- matlab simulink 温度控制时延系统 模糊pid和smith控制
- ELTEK电源维修SMPS5000SIL整流器模块故障分析及特点
- 2022/08/08 学习笔记 (day25)File类
- Transaction rolled back because it has been marked as rollback-only
- The request was rejected because the URL contained a potentially malicious String “//“
- shell function
- 电气规则
- Address Book (File Version) (C Language) (VS)
- Xray - powerful vulnerability scanning tools
猜你喜欢
随机推荐
IDEA05:线程管理
【Word】Add subscripts to the text of Word at the same time
The request was rejected because the URL contained a potentially malicious String “//“
mysql查看表的创建时间
剑指Offer-二叉树路径问题总结
C Advanced-C Language File Operation
Xray - powerful vulnerability scanning tools
A day to learn a public company: Sophia
RNN-T
matlab simulink球杆控制系统的模糊PID控制设计
MOS管的选型
中断系统结构及中断控制详解
The difference between LDO and DC-DC
Distributed timing task framework xxl-job source code analysis
el与data的
【LeetCode】169. 多数元素
电气规则
bean的生命周期
aur安装报错一个或多个文件没有通过有效性检查!
【LeetCode】1283. 使结果不超过阈值的最小除数