当前位置:网站首页>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);
边栏推荐
猜你喜欢
随机推荐
MATLAB图像处理入门
Anonymous shared memory ashmem
The request was rejected because the URL contained a potentially malicious String “//“
常用shell脚本案例解析
文件的随意读写
Chapter 7. Image-based lighting
1,C#的基本结构
筑牢安全“防火墙”河南通许县冯庄乡开展消防培训
【计算机网络-哈工大】---学习笔记(下)---(一)网络安全、密码学基础、对称、公钥、身份认证、数字签名、KDC\CA
Functions and differences of command, shell, raw, script modules, application of file, copy, fetch, synchronize
硅光电池采集用于植物叶片农残检测
IDEA05:线程管理
关于光电门的使用
力扣349-两个数组的交集——HashSet
【LeetCode】761.特殊的二进制序列
【LeetCode】1283. 使结果不超过阈值的最小除数
p67 mixin 混入/混合:两个组件共享一个配置
电气规则
3.3V控制输出5V的方法
【深度学习】聊一聊什么是卷积神经网络,卷积是什么意思?