How to stop animation in a certain frame and then resume playing?

Help me, please :) I have a flap with animation component. The animation has 60 frames and it rotates the flap 90 degrees (in frame 30) and rotates it back to 0 degrees (in frame 60). When player hits a trigger flap closes and should stop in frame30. When player goes away (triggerExit) animation should play on to trame 60. Here is my script:

var Flap1 : GameObject;

function Start(){ Flap1 = GameObject.Find("Flap1"); }

function OnTriggerEnter (other : Collider) { if(other.gameObject.CompareTag("Player")){ Flap1.animation.Play("testAnimation2"); if(Flap1.animation["testAnimation2"].time== 30){ Flap1.animation.Stop("testAnimation2"); } } } function OnTriggerExit (other : Collider) { if(other.gameObject.CompareTag("Player")){ Flap1.animation.Play("testAnimation2"); } }

Animation plays from 0 to 60 doesn't stop. By the way: in what units is the animation.time, frames or seconds?

you can stop animation on any frame you want… for example you want to stop animation at the position of very first frame. just use these line of code

//use this line to stop on very first frame which is 0.0f and the layer is 1

You can pause animation by setting animation[stateName].speed to 0, and then resume by setting it to 1. If you want it to stop playing (not just stop at particular frame), then set weight to 0 too.

I think that you should make 2 separate Animation Clips. (Animation1)One for 0-90 degrees, and the (Animation2)other for 90-0 degrees. You may want to add a Default Empty State in Animator for the Game Object’s entry.
You can make transitions from the Default Empty State to the Animations Clips using Animator transition on the basis of some parameter like trigger. Whenever you want to play the first, Just type Animator.SetTrigger(*name of the parameter*)``. And if you want to play the other. Just type Animator.SetTrigger(name of the parameter)`
That’s an easy way to do it.

Just out of curiosity, is there a reason you're rotating it through an animation component?

It seems to me you could get the functionality you're looking for through a simple script to rotate the actual object at a set rate. Your trigger could cause the flap to rotate to the closed position and then to resume rotation when the player is no longer nearby.

Maybe my image of what you're trying to do is off, but to me this would be a simpler solution (animations drive me up the wall..)