- Home /
animation to animator [mecanim]
Hi, i'm just no longer motivated for create games in unity, the new animation system is too complex, i know that i've already ask that here but i can't find a answer.
how can i simply convert that old code:
if(Input.GetKeyDown(KeyCode.R)) {
animation.clip = reloadAnim;
animation.Play();
}
to mecanim? (Just to play ONCE)
i've tryed things like ativating and desativating the mecanim bool in a coroutine but it doesn't work.
Someone can translate that code and give me the instructions on animator?
$$anonymous$$y friend. What you need to do is just watch the S$$anonymous$$lth tutorial and everything will become so clear to you. The mecanim system a LOT more user friendly and powerfull than the old one. S$$anonymous$$lth Tutorial Link
If you have to play some animation once, then yes use a boolean parameter, but you have to make transitions to exit the animation when it ends.
Answer by tanoshimi · Jan 11, 2014 at 03:18 PM
Create a new Animator state which uses your reload animation clip as its motion field.
Then, create a transition to this new state based on a trigger parameter called "Reload", and set the transition out of the reload state based on the animation exit time.
Then to transition to the reload state you just set the trigger from code:
Animator animator = GetComponent<Animator>();
if(Input.GetKeyDown(KeyCode.R)) {
animator.SetTrigger("Reload");
}
Your answer
Follow this Question
Related Questions
Is there a way to change the WrapMode of all Animations in a Mecanim Animator? 1 Answer
Edit AnimationClip during runtime from script 0 Answers
Animation Events and Mecanim 0 Answers
What is the proper way to wait for an Animator Controller to update? 1 Answer
Is there a way to abstract sprite from animation clip? 0 Answers