# Problem with coroutines unity 3d

I cannot understand why the coroutines are not waiting the designated number of seconds before executing the code below it. At the moment, the animation bleeds into the next state. I could get around this by using .time and if statements but I thought the whole point of coroutines is that you can avoid that sort of mess.

         public IEnumerator LoadBow()
{
aimStates = AimStates.Draw;
}

public IEnumerator DrawBow()
{
yield return new WaitForSeconds(this.gameObject.GetComponent<Animation>()["Draw_Bow"].length);
aimStates = AimStates.Aim;
}

public void Aiming()
{
moveTarget.SetActive(false);
switch(aimStates)
{
break;

case AimStates.Draw:
StartCoroutine(DrawBow());
break;

• You could try and use booleans with the coroutines and do checks, try creating a variable of type bool and set the boolean to true of false before the yield AND after. Then just use if statements to check specific booleans, this will allow you to wait certain amount of time and then run your code. – Vadim Tatarnikov Jul 30 '15 at 7:13
• I'm just a little confused as I thought coroutines were useful because you could dispense with booleans and if statements. I've made the code work by just dispensing with the coroutines and using my old if statement method using animation[].time as the bool. I was hoping there was a more efficient way. – OwenAlexander Jul 30 '15 at 8:33
• Well I told you my way of doing it and it works fine for me. So as I said you could set a Boolean for example to false before yield and then after the time had passed set it back to true and then just use if statement to check if the Boolean is true/false. What about efficiency, I think there's not much of a difference. From what I understand the delay from coroutine affects only something you change before and after the delay so that's why I use booleans, I find it less complicated I guess and more freedom of code. – Vadim Tatarnikov Jul 30 '15 at 8:38
• Thanks for the info. Sounds like a good strategy. I just wanted to minimize bools as I've accumulated many bugs due to excessive reliance on them. This looks like a good use of them though so I'll give it whirl :) – OwenAlexander Jul 30 '15 at 9:13

If you call coroutines this way they will be executed in order, one after another. You should fire them up with StartCoroutine(Aiming());

    public IEnumerator Aiming()
{
yield return StartCoroutine(DrawBow());
aimStates = AimStates.Aim;
}

{