Unity3d协程实现倒数计时
来源:互联网 发布:购金蝶软件会计分录 编辑:程序博客网 时间:2024/04/29 23:11
Unity3d协程的知识,不了解的同学可以在网上查找一下相关资料或者看一下Unity3D协程介绍 以及 使用。
下面介绍Unity3d协程实现倒数计时,实现代码:
public class GameManager : MonoBehaviour{ private bool _BoolIsDisplayNumber = false;//是否显示数字 private bool _BoolIsDisplayGo = false;//是否显示go private float _IntDisplayNumber; private string _StringDisplayNumber; public Texture TextNum3;//要显示的图片3 public Texture TextNum2; public Texture TextNum1; public Texture TextGo; void Start() { StartCoroutine(DisplayGameStartCountDown()); } IEnumerator DisplayGameStartCountDown() { yield return new WaitForEndOfFrame(); //显示3 _BoolIsDisplayNumber = true; _IntDisplayNumber = 3; yield return new WaitForSeconds(1f); _BoolIsDisplayNumber = false; yield return new WaitForSeconds(0.5f); //显示2 _BoolIsDisplayNumber = true; _IntDisplayNumber = 2; yield return new WaitForSeconds(1f); _BoolIsDisplayNumber = false; yield return new WaitForSeconds(0.5f); //显示1 _BoolIsDisplayNumber = true; _IntDisplayNumber = 1; yield return new WaitForSeconds(1f); _BoolIsDisplayNumber = false; yield return new WaitForSeconds(0.5f); //显示go _BoolIsDisplayGo = true; _StringDisplayNumber = "go"; yield return new WaitForSeconds(1f); _BoolIsDisplayGo = false; yield return new WaitForSeconds(0.5f); } void OnGUI() { //使用GUI显示图片 if (_BoolIsDisplayNumber) { if (_IntDisplayNumber == 3) //显示3 { GUI.DrawTexture(new Rect(Screen.width / 2 - TextNum3.width / 2, Screen.height / 2 - TextNum3.height / 2, TextNum3.width, TextNum3.height), TextNum3); } else if (_IntDisplayNumber == 2) //显示2 { GUI.DrawTexture(new Rect(Screen.width / 2 - TextNum2.width / 2, Screen.height / 2 - TextNum2.height / 2, TextNum2.width, TextNum2.height), TextNum2); } else if (_IntDisplayNumber == 1) //显示1 { GUI.DrawTexture(new Rect(Screen.width / 2 - TextNum1.width / 2, Screen.height / 2 - TextNum1.height / 2, TextNum1.width, TextNum1.height), TextNum1); } } if (_BoolIsDisplayGo) { if (_StringDisplayNumber == "go") //显示go { GUI.DrawTexture(new Rect(Screen.width / 2 - TextGo.width / 2, Screen.height / 2 - TextGo.height / 2, TextGo.width, TextGo.height), TextGo); } } }}具体实现代码如上所示,并不复杂。
在Inspector面板为Texture赋值,直接将图上拖上去就可以了。
运行效果:
这样就完成了协程实现倒数计时。不懂的同学可以私聊哦。
0 0
- Unity3d协程实现倒数计时
- 使用javascript实现简单倒数计时功能
- setInterval实现验证码倒数计时及与setTimeOut区别
- 倒数计时类
- 倒数计时进入页面
- js简单倒数计时
- 简单的倒数计时
- JavaScript倒数计时页面跳转
- 07-倒数计时跳转页面
- javascript 网页中实现一个计算当年还剩多少时间的倒数计时程序
- javascript 网页中实现一个计算当年还剩多少时间的倒数计时程序
- Unity3D 简易计时类
- 简单的页面自动跳转 倒数计时
- Jquery倒数计时按钮—setTimeout
- 简单的自定义Button 点击倒数计时
- js手机验证码倒数计时
- 使用js在网页中实现一个计算当年还剩多少时间的倒数计时程序
- Unity3D 计时/倒计时管理类
- Linux服务器开发环境搭建 Nginx+PHP+MongoDB
- Android:解决DatePickerDialog只有完成按钮、没有取消按钮的问题
- Java中线程的俩种方式,编码的变体
- Java内存泄漏例子
- 怎么把excel表格转换成word格式
- Unity3d协程实现倒数计时
- 过大数据处理
- 摄像头标定
- PAT-4C-L2-006-树的遍历(DFS)
- PendingIntent
- C/C++中标准转换运算符reinterpret_cast
- 3-认识HTML标签(2)
- VS2010安装失败
- Android理解Looper、Handler、Message三者关系: