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 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)