- Home /
Question by
Pauls · Jan 07, 2013 at 07:54 PM ·
animationbooleanstopping-animation
boolean to stop animation does not work?
Hi,
i don't understand why the animation "d1" does not work, d1 is not animating, when i set the boolean "hasPushed" to "true", so that the animation does not repeat :
function Update () {
//...
/* push */
if ( (hasPushed==false) && (Vector3.Distance(playerToFollow.position, thisTransform.position) < (dist/3) ) ){
animation.CrossFade("d1");
playerToFollow.GetComponent(official).desD = true;
hasPushed = true;/* HERE : without it, it works fine but does not stop */
/* walk */
} else if ( Vector3.Distance(playerToFollow.position, thisTransform.position) < (dist/1.3) ){
animation.CrossFade("slow");
}
How could i stop the animation with something else than a boolean?
Thanks
Comment
Best Answer
Answer by Seth-Bergman · Jan 07, 2013 at 09:02 PM
The problem is you are only playing the animation for one frame, but you want to keep playing it until it finishes... The simplest way would just be to change the Wrapmode to PlayOnce:
animation["d1"].wrapMode = WrapMode.Once;
At least I think that would be enough.. If not, you can always use normalizedTime to be SURE:
if(animation["d1"].normalizedTime == 1) //Just add this line
hasPushed = true;
...etc
hope this helps
Thanks, it finally worked with " > 0.9", thanks for the tip!