embarrassingly simple animation problem

Ok, most likely because I haven’t ever done a simple animation in Unity, I am having some problems with them.

Animation - Door sliding open
Animation - Door sliding closed.

I would like to do this with the animation editor in unity, but it is giving me some trouble. (less trouble than importing an animation though)
I have the editor figured out for basics at least. I got the animation of the door closing to work when I triggered the switch. The animation wouldnt stop looping though. I placed a wrapMode.once on it and it still wouldnt stop.

if(flip==true){
animation.wrapMode = WrapMode.Once;
animation.Play("ThickDoor01Slide");
}

So I have two questions. First, why wouldnt the wrapmode work?
Second, is it possible to make a script for an animation made in the unity editor that would basically say.
on collision play frames 1-25 and variable = true.
on collision and variable = true, play frames 30-55.

The playing specific frames is what I am after.
I searched the script reference docs, and the forums for about an hour before I broke down and posted.
Thanks for any help!

I’ve been down this road, too :slight_smile:

There is no way to get the frame number, but you can get the time using an AnimationState.

What may be of more use to you are AnimationEvents. You can trigger a function to be called at a specific time in your animation, rather than polling it. That way, you could set a trigger in the animation to stop itself.

The only gotchas with AnimationEvents is that they persist. That is, if you add AnimationEvents at the start of your game then every time you start the game you will be layering new animation events on top of the old ones, which can lead to multiple calls. There is no way to flush out the old ones as far as I know.

It’s seriously nasty that the way this occurs and I have reported it as a bug (case 230246), only to be ignored. Having AnimationEvents persist makes no sense and causes horrible behaviour!!! <----TAKE NOTE UNITY HQ!

Good luck!

Ideally there should be a flag to set for AnimationEvent to auto flush it after it’s been fired. Removing Animation Events is still missing?

Use ClampForever rather than once.