- Home /
Restore game objects after animation
In my game I have an object that, when hit by the player, has to do an animation that shrink it and then disable it (I used the animator controller and then generated my own animation). Since the game is provided with an UNDO function, I'd like to know if there is a way to restore an object to its original mesh and dimensions (i.e. before the animation). I'm a total beginner with animations so be patient! :) Thank you!
Answer by kbumpious · Sep 04, 2015 at 11:39 PM
Store the size and position in variables right before the animation is called. Then access those variables when the user clicks the undo button.
O$$anonymous$$, that's what I thought. I was wondering if there was any way to "reverse" the action of an animation.
I gotcha. Yes there is. If your animation is simple, You can just make a new one with opposite effects manually. If its complicated... Duplicate the original animation and name the new one "reverseanimation" or something Then select your new animation in the animation controller. Then in your inspector, change the speed from 1 to -1. This will mirror the original animation. You could also try -2 since usually the undo animation is faster than the original.
I don't think this is available via code though: http://docs.unity3d.com/ScriptReference/AnimationState-speed.html
Hope this is what you're looking for!
Your answer
Follow this Question
Related Questions
How to check if Animator is playing 3 Answers
How to change the color of a UI cross hair using Raycasts 1 Answer
Play Animation several times 0 Answers
Multiple Cars not working 1 Answer