- Home /
I placed the same prefab two times in my scene and only the first one animates correctly
I know this question gets asked a lot but I still couldn't fix my problem, even after searching for hours. I have a skeleton prefab and I placed two of them into my Scene. Their animations can transition from any state into hurt and dead and back through a trigger and this works with both of them. They can also transition from idle to walking and attacking through booleans and this only works for on of them. The other just stays Idle
public class Chase : MonoBehaviour {
public Transform player;
static Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
if (GetComponent<CharacterStats>().isDead) return;
Vector3 direction = player.position - this.transform.position;
float angle = Vector3.Angle(direction,this.transform.forward);
if(Vector3.Distance(player.position, this.transform.position) < 10 && angle < 90 && !player.GetComponent<CharacterStats>().isDead)
{
direction.y = 0;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
Quaternion.LookRotation(direction), 0.1f);
anim.SetBool("isIdle",false);
if (direction.magnitude > 2)
{
this.transform.Translate(0,0,0.05f);
anim.SetBool("isWalking",true);
anim.SetBool("isAttacking",false);
}
else
{
anim.SetBool("isAttacking",true);
anim.SetBool("isWalking",false);
}
}
else
{
anim.SetBool("isIdle", true);
anim.SetBool("isWalking", false);
anim.SetBool("isAttacking", false);
}
}
}
This is the code I use to set the bools. I'm guessing the first skeleton overrides the booleans set by the second, but how do I avoid that? I'm planning on making many skeletons so duplicationg the skeleton controller for every skeleton would be too much work.
Answer by Berengar03 · Jul 20, 2018 at 07:04 PM
Ok found my problem. It was because my animator was static. I don't know why I did that but now i removed the static and everything works as it should
Your answer
Follow this Question
Related Questions
Change Animator Parameters on Different Object - Prefabs 1 Answer
How create many animated objects without making for each animator controller manually ? 0 Answers
How to make horror nps with audisource? (plzs cript) 0 Answers
How to properly detect the end time of an Animation which wait for the end of the previous one ? 1 Answer