码迷,mamicode.com
首页 > 编程语言 > 详细

Unity在协程内部停止协程自身后代码执行问题

时间:2017-05-09 20:44:19      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:技术   问题   public   blog   str   top   tco   art   color   

当在协程内部停止自身后,后面的代码块还会继续执行,直到遇到yield语句才会终止。

经测试:停止协程,意味着就是停止yield,所以在停止协程后,yield之后的语句也就不会执行了。

代码如下:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class Test : MonoBehaviour {
 5 
 6     void Start () {
 7         StartCoroutine("Method");
 8     }
 9 
10     IEnumerator Method() {
11         StopCoroutine("Method");
12         Debug.Log("协程停止");
13         yield return 0;
14         Debug.Log("协程yield之后的代码");
15     }
16 }

执行结果如下:

技术分享

 

Unity在协程内部停止协程自身后代码执行问题

标签:技术   问题   public   blog   str   top   tco   art   color   

原文地址:http://www.cnblogs.com/AaronBlogs/p/6832352.html

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