I made an animation where my character is pulling out the guns from the holster and when you press the space bar the animation will play
if (Input.GetKey("w"))
animation.CrossFade ("run");
else
if (Input.GetKeyDown("Space"))
if (GunsDrawn == true)
animation.CrossFade ("DrawGuns");
else
if (GunsDrawn == false)
Now here I want to play the DrawGuns animation in reverse.
Just throwing it out there, but you could also try to add a new animation in the editor and swap the start and end times of the animation.
ie. if DrawGuns starts at 1 and ends at 200, just flip the 200 and 1 and just name it something else like HolsterGuns
You may also need to set the normalizedTime to 1 (the end of the animation) although I’m unsure if unity will then instantly stop it because it might think it’s finished. If it does change the loopMode to clamp forever.
I am having a very similar problem and I had thought about that about an hour before I ran into the problem and I had forgotten about flipping the animations, THANK YOU!!!
I’ve tried this technique several times and haven’t been able to get it to work. But then again I’ve also been unable to make an animation play in reverse by setting the speed attribute through code, so maybe there’s something up with my scene. What’s strange is that I can vary the speed of my animations as long as the value is positive, but negative speed values simply don’t play at all.
Duplicating a clip and reversing its start/end times definitely does not work, regardless of the WrapMode. This is unfortunate as it would be a relatively painless thing to do, and would require no code for changing the speed.
Regarding my previous negative speed issue, it turns out that it was working, I just didn’t notice it because it was delayed. This occured because I didn’t properly account for the reversed clip’s length. The clip’s Start=30 and End=120, so I simply set the current time to 3 seconds (120frames - 30frames = 3 seconds), then played it backwards and it ran immediately. For this to work, however, WrapMode must be set to ClampForever.