协程两种写法分析
来源:互联网 发布:三国战纪神剑升级数据 编辑:程序博客网 时间:2024/06/11 19:20
using System.Collections;using System.Collections.Generic;using UnityEngine;public class haitao : MonoBehaviour { float timee; void Start () { //由打印结果可以看出,这两个协程的计时点都是一样的,但携程内部时间起算点是累加的 StartCoroutine ("kaishi"); StartCoroutine ("kaishi"); } // Update is called once per frame void Update () { timee += Time.deltaTime; } IEnumerator kaishi(){ yield return new WaitForSeconds (2); //先等2秒 print("2秒后执行 " +timee); yield return new WaitForSeconds (5); //2秒过后 再等5秒 print("5秒后执行 " +timee); yield return new WaitForSeconds (8); //前面7秒过后再等8秒 print("8秒后执行 " +timee); }}
打印结果:
using System.Collections;using System.Collections.Generic;using UnityEngine;public class haitao : MonoBehaviour { float timee; // Use this for initialization void Start () { //由打印结果可以看出,下面三个协程的计时点都是一样的,但携程内部时间起算点是累加的 StartCoroutine(Common.DelayToInvokeDo(() => { print("2秒后执行 " +timee); }, 2f)); StartCoroutine(Common.DelayToInvokeDo(() => { print("5秒后执行 " +timee); }, 5f)); StartCoroutine(Common.DelayToInvokeDo(() => { print("8秒后执行 " +timee); }, 8f)); } // Update is called once per frame void Update () { timee += Time.deltaTime; }}
上段代码打印结果如下:
FR:海涛高软(hunk Xu)
阅读全文
0 0
- 协程两种写法分析
- 需求分析具体写法
- web地址的写法分析
- 分析交换两个整数的特殊写法
- Hql 一种错误写法的分析
- JavaWeb中Jsp使用include写法分析
- 写法
- 数据库学习:oracle的递归写法,分析函数写法,以及teradata的取一定数量记录的写法
- 实例分析SQL中除法的三种写法
- 实例分析SQL中除法的三种写法
- 内存拷贝函数不同写法的效率分析
- android.mk写法及分析--目前为止最全的
- C语言两种for循环写法分析
- Makefile之Linux内核模块的Makefile写法分析
- 分析主流css 框架 css 模块化的写法
- Makefile之Linux内核模块的Makefile写法分析
- JavaScript中(function(){…})(); 与 (function(){…}()); 写法分析
- Makefile之Linux内核模块的Makefile写法分析
- 有人闷声发大财,有人遭遇滑铁卢——2017科技领域大盘点
- 传苹果正在开发心电图仪,未来 AppleWatch 可能帮你“逃过一劫”
- CCG:2017人工智能人才报告
- Nunit3在VS2017中进行.NET Core和.NET Standard项目单元测试
- WPF之ComboBox的SelectedItem、SelectedValue、SelectedValuePath之差异
- 协程两种写法分析
- 如何为单变量模型选择最佳的回归函数
- 2017年度盘点:15个最流行的GitHub机器学习项目
- 了解神经网络中的梯度爆炸
- 利用遗传算法优化神经网络:Uber提出深度学习训练新方式
- 为给定任务自动生成神经网络:MIT提出RNN架构生成新方法
- 渡鸦音箱独家测评: 代表百度AI技术尊严的DuerOS, 用户体验真的能过关吗?
- 滚石特写: 沉默7年后, Magic Leap用魔幻现实主义式科技重新定义了自己
- Android 消息传递机制分析