- Home /
Question by
Master_of_shadows · Jan 18, 2020 at 09:51 PM ·
animationanimatornpcs
how to animate multiple NPC's, each one with different animation?
I created a zombie NPC and imported the animation, the animation is working fine when I have one zombie on the field, but when multiple zombies are spawned the animation gets mixed and when I shoot one, another zombie plays the animation of death while the dead one doesn't.
static Animator anime;
private Vector3 curpost;
private Vector3 lastpost;
public bool dead;
public Transform player;
public NavMeshAgent agent;
// Start is called before the first frame update
void Start()
{
anime = GetComponent<Animator>();
lastpost = transform.position;
if (player == null)
{
player = GameObject.FindGameObjectWithTag("Player").transform;
}
if (agent == null)
{
agent = GetComponent<NavMeshAgent>();
}
anime.SetBool("isDead", false);
}
// Update is called once per frame
void Update()
{
Debug.Log(anime.GetBool("isDead") + " " + gameObject.name);
if (dead)
{
GetComponent<NavMeshAgent>().enabled = false;
}
else
{
curpost = transform.position;
if (curpost != lastpost)
{
anime.SetBool("isRunning", true);
}
else
{
anime.SetBool("isRunning", false);
}
agent.SetDestination(player.position);
lastpost = transform.position;
}
}
public void Dead()
{
anime.SetBool("isDead", true);
Invoke("destroy", 4.0f);
}
private void destroy()
{
Destroy(gameObject);
}
public void attack()
{
anime.SetTrigger("attack");
}
Comment
Best Answer
Answer by Master_of_shadows · Jan 24, 2020 at 01:28 PM
I found the problem guys the animator is static, and it shouldn't be. as static saves, the last NPC spawned.
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Dynamically add AnimationState to Controller 0 Answers
How can i pay a animation again and agan? 1 Answer
Animator moves feet even when it's not supposed to 0 Answers