x


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?

more ▼

asked Feb 09 '11 at 05:07 PM

EytanTKing gravatar image

EytanTKing
24 9 13 21

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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");
more ▼

answered Feb 09 '11 at 06:39 PM

Bunny83 gravatar image

Bunny83
45.1k 11 48 206

That didn't work for me, so I just made the and animation cancel its self.

Jun 27 '11 at 06:24 PM EytanTKing

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.

Jun 27 '11 at 06:39 PM Bunny83

Yes the animation stopped, but after words when the player collided with the door it played the animation again.

Jun 29 '11 at 06:39 AM EytanTKing
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3771
x3446
x2485
x192
x10

asked: Feb 09 '11 at 05:07 PM

Seen: 1234 times

Last Updated: Jun 29 '11 at 06:39 AM