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");
}
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..)