When I shoot the enemy ai the animation plays . But the problem is that the enemy ai follow the player after it dies . Here is the move and attack script :
using UnityEngine;
using System.Collections;
public class Enemyai : MonoBehaviour {
public Transform player;
static Animator anim;
public NavMeshAgent nav;
void Start ()
{
anim = GetComponent ();
}
void Update ()
{
if (Vector3.Distance(player.position, this.transform.position) < 13)
{
Vector3 direction = player.position - this.transform.position;
direction.y = 0;
this.transform.rotation = Quaternion.Slerp (this.transform.rotation,Quaternion.LookRotation(direction), 0.1f);
anim.SetBool("isIdle",false);
if(direction.magnitude > 2.6 )
{
nav = GetComponent ();
nav.SetDestination (player.position);
anim.SetBool("isMoving",true);
anim.SetBool("isAttack",false);
}
else
{
anim.SetBool("isAttack",true);
anim.SetBool("isMoving",false);
}
}
else
{
anim.SetBool("isIdle",true);
anim.SetBool("isMoving",false);
anim.SetBool("isAttack",false);
}
}
}
↧