is there a way in Unity to access the Motion clip of an Animator State and change it at runtime via script? I am trying to do a character shop in my 2D game. My idea is, when i click a GUI button it would just select different motion clips but the states would stay the same. It's just a simple Jump and Idle state, parameters dont change. I just want to feed in different animation clips for different characters.
1 Answer
\$\begingroup\$
\$\endgroup\$
1
Yes, but you would do this via the Mechanim state machine. Create a transition and set it to change via a Trigger.
Doing it this way, when you want to swap animation states, you simply do this:
Animator.SetTrigger ("Swap");
If you want to set the Animator Motion directly, it is a little more complicated. You will need to create Animation Controllers, and then swap them using the AnimatorOverrideController.
-
\$\begingroup\$ I used the AnimatorOverrideController and it works! Thank you. \$\endgroup\$ Commented Sep 26, 2016 at 13:15