我怎么能有一个能够播放协同程序的功能,但首先检查它是否已经在运行以阻止协同程序?
编辑:抱歉,我没有看到有人已经问过/已经回答了这个问题,这是我被困了一段时间
答案 0 :(得分:1)
public class Example : MonoBehaviour
{
[SerializeField] // Allow the variable to be edited in editor
private float parameterValue;
private IEnumerator coroutine;
private IEnumerator CoroutineA(float _parameter)
{ // do something, usually for _parameter time }
private void StartDoSomething ()
{
if (coroutine != null)
StopCoroutine(coroutine); // no overlaps on timers etc
coroutine = CoroutineA(parameterValue);
StartCoroutine(coroutine);
}
}
或看到链接的答案: How to stop co-routine?