IEnumerator not printing

I’m trying to make a simple test, where it prints at the end of every animation. The current animation I have is in a loop when it plays.

	IEnumerator Test() 
	{
        //not printing
		while(animation.IsPlaying("Attack"))
		{
			yield return new WaitForSeconds(animation["Attack"].length);
			Debug.Log("Done");
		}

        //working
		Debug.Log("Hello");
		yield return new WaitForSeconds(3);
		Debug.Log("It's been 3 seconds");
	}

Change your “While” to “If”.

Also be sure you have StartCoroutine(Test()); somewhere, like the start function. However put it wherever you want to call it.

I suspect that either animation.IsPlaying(“Attack”) is returning false or animation[“Attack”].length is too large - also can you show how you’re calling/invoking this Test() method?

I would add some additional trace printing to see if where the error exists, like so:

IEnumerator Test() 
{
  //not printing

  // Add
  Debug.Log("attack is: " + animation.IsPlaying("Attack"));
  while(animation.IsPlaying("Attack"))
  {
    // Add
    Debug.Log("Waiting for: " + animation["Attack"].length);
    yield return new WaitForSeconds(animation["Attack"].length);
    Debug.Log("Done");
  }

  //working
  Debug.Log("Hello");
  yield return new WaitForSeconds(3);
  Debug.Log("It's been 3 seconds");
}