How do I pause a method?

Hello all,

I have an animate method that animates a GameObject. It can also triggers the end of the animation.

I want to make a method that starts the animate, pause the method and when the animation is finished to continue. Something like that

myMethod() {

animate(GameObject);
// wait-pause (that is what’s missing);
Debug.Log(“hello”);

}

I did this but it didn’t work:

I had a ‘bool isAnimating’ = true; When the animation finished it changed it to false;
In the wait/pause section I started a Coroutine WaitUntil(() => isAnimating = false);

But of course the problem is that, even though the Coroutine was working as expected, the “hello” world was being typed at the same time as the animation was starting.

So how can I pause the program and continue it when the animation is being finished?

Thank you

John

You can nest/chain coroutines. ie. yield to a coroutine from within a coroutine.

IEnumerator MyMethod() {

	yield return StartCoroutine(AnimateMyObject()); //This will wait until "AnimateMyObject" is finished
	Debug.Log("hello");

}

IEnumerator AnimateMyObject()
{
	//Animate the object here
}