StopCoroutine. how avoid to stop all my coroutines?

StopCoroutine stops all coroutines in the same behaviour, like it is said in this post and others similar:

link text

Just beware that if the same coroutine is called more than once using this method, then using StopCoroutine will result in all of them being stopped.

I am using the string call method, but it happens the same way using the IEnumerator call method.

Any idea how to stop just 1 coroutine and not all?

I’ve never used a StopCoroutine statement from inside the coroutine, and haven’t seen such usage anywhere. I think this might be the problem.

You should use yield break instead of StopCoroutine to stop the coroutine from inside the coroutine.

BTW it would also be a good idea to have the Destroy (planetaTrozosGameObject) before the yield break

The best way is to hold a reference to the IEnumerator and stop just that one, for example.

//IEnumerator object to hold coroutine
private IEnumerator myCoroutine;

//Assign IEnumerator to the coroutine
private void SomeMethod()
{
        myCoroutine = WaitAndPrint(3.0f);
       StartCoroutine(myCoroutine);
}

//Kill the specific instance of the coroutine set earlier
private void StopCoroutine()
{
        StopCoroutine(myCoroutine);
}

Further reading here.

Thanks so much.

It worked. I didn’t know the yield break statement usage.

It also worked with the string method coroutine call.

Thanks again.