My problem is, that I have a simple coroutine eg. like this one:
public IEnumerator Test()
{
while (???)
{
Debug.Log("coroutine");
yield return null;
}
}
I have an update cycle as well:
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(Test());
}
}
So currently as you see it’s working, when I push the mousebutton down, the above coroutine will be started. But I’m in trouble because I would like to solve, that if I push the button down, the actually running coroutine should be stopped before running the coroutine again.
I know, that there is a stopcoroutine method in Unity, but I think, the concept of the coroutines is the conditions, and not the forced stop.
Don’t use StopCoroutine(). It only accepts a string, which means you have to invoke StartCoroutine with a string name (e.g., StartCoroutine(“Test”)), which is prone to typo bugs.