StopCoroutine not working.
I want to instantiate while the coroutine is running, then when the coroutine stops running it should stop instantiating the gameobject. But it continues to instantiate them even after I call StopCoroutine. Any thoughts on why this is happening? Am I using StopCoroutine correctly?
public IEnumerator Attack1()
{
//Smash Right
Instantiate(damageZoneGoRightLong, new Vector3(transform.localPosition.x + 4, -5.25f, 1), transform.rotation);
yield return new WaitForSeconds(1);
StartCoroutine(Attack2());
StopCoroutine(Attack1());
}
public IEnumerator Attack2()
{
//Swipe Left
Instantiate(damageZoneGoLeft, new Vector3(transform.position.x, -5.25f, 1), transform.rotation);
yield return new WaitForSeconds(3.5f);
StartCoroutine(Attack3());
StopCoroutine(Attack2());
}
Based on my tests, the code you have here isn't what is causing the repetition. You don't even have to call StopCoroutine, since the couroutine would end there anyway.
Where are you calling the coroutine to begin with?
You were correct, I was accidentally calling Attack1 multiple times. I will select this as best answer if you make it an answer.
Your answer
Follow this Question
Related Questions
After stop coroutine it resumes its task when I call start coroutine 1 Answer
Coroutine not stopping 0 Answers
Multiple objects being instantiated instead of one 0 Answers
Insantiate Loop Issue 0 Answers