I need to enable the nav mesh obstacles on my enemy ai and set the destination in the script as well . I declare nav mesh as a variable already . I need help with the rest . Here is my script :
using UnityEngine;
using System.Collections;
public class Enemyai : MonoBehaviour {
public Transform Player;
Animator anim;
public NavMeshObstacle nav;
void Start ()
{
anim = GetComponent<Animator> ();
}
public void Stop(){
anim.SetBool("isMove", false);
anim.SetBool("isAttacking", false);
anim.SetBool("isIdling", true);
this.enabled = false;
//Or if you want to destroy the AI script completely
//Destroy(this)
}
void Update ()
{
float speed = 0.9f;
if (Vector3.Distance(Player.position, this.transform.position) < 10000f)
{
nav = GetComponent <NavMeshObstacle> ();
nav.SetDestination (Player.position);
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("isIdling",false);
if(direction.magnitude > 2 )
{
this.transform.Translate(0,0,0.15f);
anim.SetBool("isMove",true);
anim.SetBool("isAttacking",false);
}
else
{
anim.SetBool("isAttacking",true);
anim.SetBool("isMove",false);
}
}
else
{
anim.SetBool("isIdling",true);
anim.SetBool("isMove",false);
anim.SetBool("isAttacking",false);
}
}
}