- Home /
Using coroutines to do attack patterns
I'm making a boss but for one of his phases I want him to do a series of attacks one after another. The first attack will be done for 5 seconds and then he will start doing a different attack for 5 seconds again. And once the entire coroutine is complete it will stop.
Current I am doing this:
IEnumerator HandleFTPatternState() {
FTPattern1();
yield return new WaitForSeconds(5f);
FTPattern2();
yield return new WaitForSeconds(5f);
FTPattern3();
yield return new WaitForSeconds(5f);
FTPattern4();
yield return new WaitForSeconds(5f);
}
This does go to the other attack pattern however he still does the previous one as well at the same time. How would I make it so that he only does say FTPattern3()
once he gets to it and not FTPatter1()
and FTPattern2()
at the same time?
I've dabbled in Co-Routines, but not enough to be able to help you. From what I see, this should work. However since it's not working then that means that there's a problem I'm not seeing.
$$anonymous$$y theory is that you must be calling StartCoroutine more than once, so maybe you have two Co-Routines running at the same time. (I don't know if this is possible, as I've said before, I've only dabbled in Co-Routines)
I just googled if you can start a Co-Routine multiple times and you can. So make sure you don't call the Co-Routine twice.
Answer by text23d · Nov 30, 2017 at 06:13 PM
I would have used Animation events in your case. Just in the end of animation (make sure to make a copy of anim file - Ctrl+d) make anim event, and start playing next animation from the function selected. IMHO this may help (yes, and make time variable to count seconds)
Your answer
Follow this Question
Related Questions
WaitForSeconds not working in IEnumerator function using MoveNext 1 Answer
Coroutines WaitForSeconds – uneven spacing 2 Answers
How to stop a coroutine started in Script A from within Script B 1 Answer
Can't get past WaitForSeconds in my coroutine 1 Answer
Coroutine doesn't work when called from another method. 3 Answers