How can I switch animations while program is running on a game object?
Hello, I am trying to switch Animations while a GameObject / Sprite is running during game play.
In example:
I have a sprite that can move around with it's animations, but when the player presses a certain key, the sprite changes. I understand how to make a new animation file, and I have attempted something along the lines as, creating two separate Animations like.....
public Animation nessWalkAnimation;
public Animation nessBikeAnimation;
but when in Unity I can't even assign new animations to these objects. I want to have a new animation file that changes when the sprite changes on the button press. Any help is greatly appreciated!
Answer by UsmanAbbasi · Jan 01, 2016 at 06:44 AM
You should use Animator component. Make a state machine and use it to switch animations through code. If you have not used Animator before then this can help you. https://unity3d.com/learn/tutorials/modules/beginner/animation/animator-controller
Thanks, I wasn't thinking and added a bool to check whether the player was on the bike or not and changed the animation accordingly...durrr.