- Home /
Canceling animation.Play functions after being used
I've used this as a door opening script:
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Door")
{
hit.gameObject.animation.Play("Door_Open");
}
}
How do I cancel the "hit.gameObject.animation.Play("Door_Open");" function after the animation been played?
Answer by Bunny83 · Feb 09, 2011 at 06:39 PM
A function can't be "canceled" from outside the function, but that's not necessary. Play() just starts the animation. With Stop() you can stop a running animation at anytime.
But i guess you just want the animation to stop automatically at the end. You have to set the wrapmode of your animation to WrapMode.Once, that's all.
In your case it should be
hit.gameObject.animation["Door_Open"].wrapMode = WrapMode.Once;
hit.gameObject.animation.Play("Door_Open");
That didn't work for me, so I just made the and animation cancel its self.
What do you mean with "it didn't work"? What did not work? If the wrapmode is set to once the animation will cancel itself when it's finished.
Yes the animation stopped, but after words when the player collided with the door it played the animation again.