This isn’t so complex as it sounds. I have an animation Component and I want to wait till an animation that is playing to stop.
This is my code:
function WaitForAnimation ( animation : Animation)
{
yield; while ( animation.isPlaying ) yield;
}
...
...
hit.collider.gameObject.animation.PlayQueued(animationToPlay);
WaitForAnimation(hit.collider.gameObject.animation[animationToPlay]);
The thing is that hit.collider.gameObject.animation[animationToPlay]
is of type AnimationState and while I need to wait for the specific animation to stop playing. There are 5 or 6 animations attached to my gameObject and I don’t really care which one is currently playing, I just need to wait for the current playing animation to stop.
I tried with simply putting WaitForAnimation(hit.collider.gameObject.animation);
but the function exits immediately, without really waiting for the animation to finish.
What I am trying to do is the following:
I have 4 separate animations. Each one of these rotates the object 0->90 or 90->180 or 180->270 or 270->360 (that’s why 4 different animations).
When the object for some reason needs to be animated from 0->90 and then immediately from 90->180, the 0->90 animation doesn’t manage to complete to its time. So a hiccup is being observed from x (where x is between 0 and 90, and represents the 1st animation’s angle when the 2nd animation started being rotated) to 90, which is the 2nd animation’s starting angle.
So, that’s why I used PlayQueued() so as to wait for each animation to finish before the next to start.
But, I have problems with the accuracy of it. For example, if I play the 1st 3 animations simultaneously (with PlayQueued()) and wait for all to finish, I observe angles of 271,1234 and such. That’s why I wanted to have WaitForFinish, so as to manually fix the angles of the objects.
But, if there is a way to fix the PlayQueued accuracy issue, it would be preferred.