【发布时间】:2013-11-13 07:25:26
【问题描述】:
我不明白为什么。
我已经阅读了很多关于它的文档,并且有很多 cmets
StopCoroutine(string) 只能停止以 StartCoroutine(string) 开头的协程
代码如下。
在 CharTouchControl.cpp 类中
if( Input.GetKeyDown( KeyCode.Q ) )
{
_CharControl.StartCoroutine("useFever", 10);
}
_CharControl 是 CharTouchControl 的成员,当然 _CharControl 引用了下面的 CharControl 实例。
和 InClass CharControl
public IEnumerator useFever(float _duration = 10)
{
if( m_nUseFever < _nFeverMax )
{
Debug.Log("Stop!!");
StopCoroutine("useFever");
yield return new WaitForEndOfFrame();
}
m_fgCharState = CharState._FEVER;
// fever particle
m_psFeverPaticle.Simulate(4);
yield return new WaitForEndOfFrame();
} // end of useFever
当 m_nUseFever
但协程不会停止并模拟颗粒。
有人帮忙吗?
【问题讨论】:
-
只是出于好奇,你为什么在协程内部使用
StopCoroutine?在第一个if语句中使用yield break。 -
您调用
StopCoroutine,这会阻止函数的其余部分(包括粒子模拟)执行。你想达到什么目的?