本文介绍了如何停止合规?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当两人合作程序正在运行,你怎么停止第一次合作例行?
GLOBALS.stableTime = 5 ;
的IEnumerator StableWaittingTime()
{
收益回报新WaitForSeconds(1F);
如果(GLOBALS.stableTime == 0){
GameManager.instance.LevelFaildMethod();
}其他{
GameManager.instance.stableWaittingTime.text = GLOBALS.stableTime.ToString();
GLOBALS.stableTime--;
StartCoroutine(StableWaittingTime);
}
}
解决方案
@ Imapler 答案几乎是你所需要的。我只想补充一点, StopCoroutine
的方法 MonoBehaviour
是超载,有3个类型的参数,所以可能停止同名的很多协同程序。
。对于在这里您需要,只需使用产量突破;像这样的:
无效的start()
{
StartCoroutine(StableWaittingTime());
}
的IEnumerator StableWaittingTime()
{
收益回报新WaitForSeconds(1F);
如果(假)
{
//做些什么
}
,否则
{
//做些什么
StartCoroutine( StableWaittingTime());
产量突破;
}
}
When two co-routines are running, how do you stop the first co-routine?
GLOBALS.stableTime = 5;
IEnumerator StableWaittingTime ()
{
yield return new WaitForSeconds (1f);
if (GLOBALS.stableTime == 0) {
GameManager.instance.LevelFaildMethod ();
} else {
GameManager.instance.stableWaittingTime.text = GLOBALS.stableTime.ToString ();
GLOBALS.stableTime--;
StartCoroutine ("StableWaittingTime");
}
}
解决方案
@Imapler answer is almost all you need. I would just add that StopCoroutine
method of MonoBehaviour
is overloaded and has 3 types of parameters, so it is possible to stop many coroutines of same name.For your need here, just use yield break; like this:
void Start ()
{
StartCoroutine (StableWaittingTime ());
}
IEnumerator StableWaittingTime ()
{
yield return new WaitForSeconds (1f);
if (false)
{
// do something
}
else
{
// do something
StartCoroutine (StableWaittingTime ());
yield break;
}
}
这篇关于如何停止合规?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!