Stop单个Coroutine

简介:

public Coroutine StartCoroutine(string methodName, object value = null);

Description
Starts a coroutine named methodName.

In most cases you want to use the StartCoroutine variation above. However StartCoroutine using a string method name allows you to use StopCoroutine with a specific method name. The downside is that the string version has a higher runtime overhead to start the coroutine and you can pass only one parameter.

// In this example we show how to invoke a coroutine using a string name and stop it

function Start () {

StartCoroutine("DoSomething", 2.0);
yield WaitForSeconds(1);
StopCoroutine("DoSomething");

}

function DoSomething (someParameter : float) {

while (true) {
    print("DoSomething Loop");
    // Yield execution of this coroutine and return to the main loop until next frame
    yield;
}

}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {

IEnumerator Start() {
    StartCoroutine("DoSomething", 2.0F);
    yield return new WaitForSeconds(1);
    StopCoroutine("DoSomething");
}
IEnumerator DoSomething(float someParameter) {
    while (true) {
        print("DoSomething Loop");
        yield return null;
    }
}

}
本文转自jiahuafu博客园博客,原文链接http://www.cnblogs.com/jiahuafu/p/6743536.html如需转载请自行联系原作者

jiahuafu

相关文章
|
4月前
|
Python
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
54 0
|
5月前
|
存储 弹性计算 运维
sleep命令
【4月更文挑战第29天】
29 0
|
移动开发 JavaScript 前端开发
说说你对事件循环event loop的理解?
说说你对事件循环event loop的理解?
97 0
|
PHP
swoole,swoole_timer_tick() must be callable, array given 报错异常
easyswoole框架内部交流后也说明这个问题是由于swoole版本变动,很早以前就在新版做了兼容(将intervalCheck改为public方法)
176 0
|
JavaScript
【说说你对事件循环event loop的理解】
【说说你对事件循环event loop的理解】
|
JavaScript 前端开发
说说你对事件循环的理解(event loop)
说说你对事件循环的理解(event loop)
浅析Event Loop(事件循环)
浅析Event Loop(事件循环)
99 0
|
Java
Java线程中的run()和start()区别
Java线程中的run()和start()区别
80 0
|
Java 开发者
为什么不推荐使用 stop、suspend 方法中断线程?
我们知道像stop、suspend这几种中断或者阻塞线程的方法在较高java版本中已经被标记上了@Deprecated过期标签,那么为什么她们曾经登上了java的历史舞台而又渐渐的推出了舞台呢? 到底是人性的扭曲还是道德的沦丧呢,亦或是她们不思进取被取而代之呢,如果是被取而代之,那么取而代之的又是何方人也,本文我们将一探究竟。
240 0
为什么不推荐使用 stop、suspend 方法中断线程?
|
消息中间件 JavaScript 前端开发
Event loop事件循环
线程 javascript是单线程语言,也就是说同一个时间只能做一件事情,而这个单线程的特性与它的用途相关,作为浏览器脚本语言,javascript的主要用途是与用户互动,以及操作DOM。
1376 0