Hey guys ![]()
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 ![]()
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! ![]()
EDIT:
Edited the && condition to || but it still donβt work ![]()
Don't you forget to call
β thomlaurent95WaitForAnimationwithStartCoroutine(WaitForAnimation())? Be careful the "&&" operator you set will exit the loop if one condition at least is completed, not sure if it's what you expectsYeah I start it with StartCoroutine(WaitForAnimation())^^ And o.O I thought by && both condition have to be true^^ Did I misunderstood the basics XD? But yeah your right, by testing the script it goes out of the "while do", when only one condition is true :(
β DarkkingdomA && B evaluates to true if both A and B are true. Do-While (condition) loops will continue executing only if the condition is true. So Do-While (A&&B) will keep running only while both A and B are true. You might be after ||. Do-While (A||B) will keep running if either A or B is true. Note that Do-While will execute at least once, regardless of what the condition is. This is different from While, which will not execute if the condtion is false.
β KiwasiOh god^^ yeah your right that was a problem^^ But it sadly dont solve my problem :( The do/while runs one time and than it goes out of the loop. Even if I only query "while (animationTimer < currentStateTime);" But "while (transform.position != attackEndPos);" works until its reach the target point and thats how it should be. Mhhh I dont get why the animation query wont work :(
β DarkkingdomTry to debug the values for animationTimer and currentStateTime.
β HarshadK