As you can see in the video. If I duplicate them so all of the new AI is going to be freezing.
This is my code that using for these AI.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class chase : MonoBehaviour {
public Transform player;
static Animator anim;
public Slider healthbar;
void Start ()
{
anim = GetComponent<Animator>();
}
void Update ()
{
if (healthbar.value <= 0) 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 <160)
{
direction.y = 0;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
Quaternion.LookRotation(direction), 0.5f);
anim.SetBool("isIdle", false);
if (direction.magnitude > 1)
{
this.transform.Translate(0, 0, 0.02f);
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);
}
}
}
Sorry for my bad English.