For some reason in my script, the WaitWhile and WaitUntil does not work properly. I am trying to wait until the animation is “DropBuilding” and then wait while it is not finished. Sometimes, the code just stops there when the animation has already finished playing and nothing happens. Here is the code:
Debug.Log("Animation starting to play.");
// Waits until the current animation is DropBuilding.
yield return new WaitUntil(() => previewAnimator.GetCurrentAnimatorStateInfo(0).IsName("DropBuilding"));
// Waits till animation has finished playing.
yield return new WaitWhile(() => previewAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f);
Debug.Log("Animation has finished.");