public class ZombieFollow : MonoBehaviour {
public GameObject ThePlayer;
//public GameObject TheEnemyHead;
public float TargetDistance;
public float AllowedRange = 10.0f;
public GameObject TheEnemy;
public float EnemySpeed;
public static int AttackTrigger;
//public static bool isDead = false;
public RaycastHit shot;
private void Start()
{
}
private void Update()
{
transform.LookAt(ThePlayer.transform);
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out shot))
{
TargetDistance = shot.distance;
if (TargetDistance < AllowedRange && AttackTrigger < 2)
{
EnemySpeed = 0.02f;
if (AttackTrigger == 0)
{
TheEnemy.GetComponent<Animation>().Play("walk");
transform.position = Vector3.MoveTowards(transform.position, ThePlayer.transform.position, EnemySpeed);
}
}
else
{
EnemySpeed = 0f;
}
}
if (AttackTrigger == 1)
{
TheEnemy.GetComponent<Animation>().Play("attack");
}
if(AttackTrigger == 2)
{
TheEnemy.GetComponent<Animation>().Play("back_fall"); // вот здесь он должен остановиться и не идти дальше никуда.
}
}
private void OnTriggerEnter(Collider other)
{
AttackTrigger = 1;
}
private void OnTriggerExit(Collider other)
{
AttackTrigger = 0;
}
}