1
\$\begingroup\$

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.

enter image description here

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Yes, but you would do this via the Mechanim state machine. Create a transition and set it to change via a Trigger.

enter image description here

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.

\$\endgroup\$
1
  • \$\begingroup\$ I used the AnimatorOverrideController and it works! Thank you. \$\endgroup\$
    – Richarrd82
    Commented Sep 26, 2016 at 13:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .