- Home /
While loop interfering with Mecanim?
Hey,
So I have a function that sets a boolean for the object's animator, causing the object to go through a sequence of animations. Here it is:
function Wave (){
anim.SetBool("Wave", true);
Debug.Log("wave");
walkingBack = true;
}
This works perfectly fine and does what I expect. However, as soon as I add a while loop to the function it stops to work. And I don't mean that just the code inside the loop is not executed, the code outside of the loop is not executed either, Wave is never set to true. Not even the Debug Log works, despite the fact that it is outside the while loop, and called before it.
function Wave (){
anim.SetBool("Wave", true);
Debug.Log("wave");
walkingBack = true;
while (walkingBack == true){
if(transform.position.x < startPositionX - walkDistance){
anim.SetBool("Turn Right", true);
walkingBack = false;
}
yield;
}
}
As soon as I comment out the while and yield statements then it works fine again, so I'm definitely sure it is a problem with the while statement, however I've used code before that had almost exactly the same structure which worked fine so I can't understand what is going wrong.
Does anyone know what's going on?
Your answer
Follow this Question
Related Questions
Mecanim animation keeps running infinite 1 Answer
How can I change a mecanim animation by pressing a key? 1 Answer
Turn off root motion for a specific animation 4 Answers
Timing animations with mecanim 0 Answers
mecanim animation problem 0 Answers