- Home /
Animator Controller playing different clips with same names?
I have a few 3D game objects that has same names for its clips.
As I intend to make different units that shares practically the same animation setup (same bools, triggers and others..) I'm hoping to do this without manually making nearly same animator controller for every units.
For example, my typical animator controller has 2 bool values, "moving" and "attacking" respectively and 3 animation clips for them so that they can have "idle","running","attack" motions. So if I were to add new monsters or characters, I only need to change their reference clips and their animation would work flawlessly with the same unit script.
Is this possible? If so, please do guide me.
Answer by zeman97 · Dec 26, 2014 at 07:23 AM
Yes, it's actually quite simple, the code would be as follows:
public bool isMoving = false;
public bool isRunning = false;
void Update()
{
//The character is moving.
if(isMoving)
{
//The character is running.
if(isRunning)
{
animation.Play("running_anim");
}
//The character is walking.
else
{
animation.Play("walking_anim");
}
}
//The character is not moving.
else
{
animation.Play("idle_anim");
}
}
As for set up in the editor. Lets say you had three prefabs, all using animations with the same name, because these animations have the same name, they must be kept in separate folders. For example you could have a folder for each prefab that holds the prefab and the animations for that prefab.
Almost forgot to mention, all the animations must share the name used in the code.
Well, I was hoping for animator controller not animation setup, but thanks for re$$anonymous$$ding me that I can do this if I can't find any alternatives.
Your answer
![](https://koobas.hobune.stream/wayback/20220613174915im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
After working in animator controller, sprite won't appear in game mode 0 Answers
problems to generate and apply Animation clip in build(standalone) 0 Answers
i need help with make an attack animation only when the player is near 1 Answer
Animation: transitioning to a given moment in the animation 1 Answer