当前位置:网站首页>untiy countdown
untiy countdown
2022-08-09 06:01:00 【Wu Zimu】
实现例如 01:30:50的倒计时
/// <summary>
/// countdown text box
/// </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>
/// Set the countdown coroutine
/// </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();
}
The method is called when usedSetCountDown();
例如
SetCountDown(3670);
边栏推荐
猜你喜欢
随机推荐
mysql查看表的创建时间
金仓数据库能否设置事务自动提交
【深度学习】聊一聊什么是卷积神经网络,卷积是什么意思?
5G对物流行业的积极影响
kubernetes apparmor入门
【Feel】Unity Feel插件中,Camera无法正确显示CameraShake
excel表格如何不需鼠标往下拖动而自动往下填
八、开发者工具与单元测试
S7-200SMART PLC Modbus TCP通信
二十四节气之立秋
磁性核壳四氧化三铁颗粒负载金纳米星|磁性Fe3O4-POSS-COOH|超顺磁四氧化三铁聚多巴胺核壳结构纳米粒子
找两个单身狗
文本字符串长度排序 - 在线工具
S7-200SMART PLC Modbus TCP communication
文件的随意读写
【JMeter】jmeter测试 - 上传多个图片/批量上传图片接口 CSV文件参数化方法
22年下高项论文题目预测
【Word】Word 正文中同时加上下标
直播平台怎么搭建,设置状态栏颜色、沉浸式状态栏
Introduction to AIOT