Do while animation is not finished

Hey guys :slight_smile:

I have problem with my IEnumerator function.
It should play the animation and move the player,
so long the player is not reaching his end position and the animation is not finished.

It works perfekt when I only query the endPos, but the query with the animation length wont work :frowning:

The currentStateName and Phase is set before calling the IEnumerator (Thats not the problem ^^)

Here is my code:

	AnimatorStateInfo currentState;
	string currentStateName;
	int currentStatePhase;
	float currentStateTime;
	
float animationTimer;


IEnumerator WaitForAnimation ()
    	{
    						
    		currentStateTime = currentState.length;
    
    		do
    		{
    
    			Moving();
    			animationTimer = animationTimer + Time.deltaTime;
    			animator.SetInteger (currentStateName, currentStatePhase);
    
    			yield return null;
    			
    		}while (transform.position != EndPos || animationTimer < currentStateTime); 
    			
    		//Happens when reached attackEndPos and animation finished
    			animationTimer = 0;
    			animator.SetInteger (currentStateName, 0);
    
    	}

Thank you so much for your time! :slight_smile:

EDIT:
Edited the && condition to || but it still don’t work :frowning:

From the informations you gave, I suppose the problem is you don’t do an initialization on your animationTimer like this before your loop starts :

animationTimer = 0;

It’s the only way I found to get your “while (animationTimer < currentStateTime);” wrong at the first iteration.