码迷,mamicode.com
首页 > 其他好文 > 详细

用携程来启动一个监听程序

时间:2016-12-25 07:43:45      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:coroutine   结束   put   null   ret   out   void   while   color   

 

1.启动携程 监听空格键 一旦空格键按下 就运行程序 然后携程结束

 1 void Start()
 2 {
 3 StartCoroutine(测试携程());
 4 
 5 }
 6 
 7  
 8 
 9 IEnumerator 测试携程()
10 {
11 Debug.Log("携程被激活了");
12 
13 while(!Input.GetKeyDown(KeyCode.Space)) //监听到一个事件 就结束携程
14 yield return null;
15 
16 Debug.Log("携程响应了");
17 
18 }

 

2.启动携程 监听空格键 一旦空格键按下 就运行程序 携程不关闭 继续监听

 

 1 void Start()
 2 {
 3 StartCoroutine(测试携程());
 4 
 5 }
 6 
 7  
 8 
 9 IEnumerator 测试携程()
10 {
11 Debug.Log("携程被激活了");
12 
13  
14 
15 while (true)
16 {
17 if (Input.GetKeyDown(KeyCode.Space))
18 {
19 Debug.Log("携程响应了");
20 }
21 yield return null;
22 }
23 
24  
25 
26 }

 

用携程来启动一个监听程序

标签:coroutine   结束   put   null   ret   out   void   while   color   

原文地址:http://www.cnblogs.com/vsdog/p/6218965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!