I am having a problem rooting my enemy ai in my scene, What going is I got an animation attach to my enemy and what is happening it every time I kill the enemy ai the animation takes over the coordinates and moves the object back to 0,0,0 . I created a empty gameobject drag the child into the empty gameobject. I know need to make some changes in the inspector . I have a pic here to show where I am at .
-
You should attach Patrol.cs to Enemy
-
Meanwhile you should create way points manually or by using WaypointCircuit.cs script
-
Below i attached screenshots of InspectorView. Based on that you can arrange your enemy characters.
//Patrol.cs
using UnityEngine;
using System.Collections;public class Patrol : MonoBehaviour {
public Transform[] points; private int destPoint = 0; private NavMeshAgent agent; //public NavMeshAgent agent2; Animator m_Animator; public Transform target; void Start () { agent = GetComponent<NavMeshAgent>(); //agent.updatePosition = false; // Disabling auto-braking allows for continuous movement // between points (ie, the agent doesn't slow down as it // approaches a destination point). agent.autoBraking = false; m_Animator = GetComponent<Animator>(); GotoNextPoint(); } void GotoNextPoint() { // Returns if no points have been set up if (points.Length == 0) return; // Set the agent to go to the currently selected destination. agent.destination = points[destPoint].position; // Choose the next point in the array as the destination, // cycling to the start if necessary. destPoint = (destPoint + 1) % points.Length; } void Update () { // Choose the next destination point when the agent gets // close to the current one. if (agent.remainingDistance < 0.5f) GotoNextPoint(); if (hero.erun == true) { m_Animator.SetBool ("run", true); agent.speed = 3; transform.LookAt(target); } else { m_Animator.SetBool ("run", false); agent.speed = 2; } if (hero.eattack == true) { m_Animator.SetBool ("attack", true); agent.speed = 0; //agent.updatePosition = false; //transform.LookAt(Vector3.zero); } else { m_Animator.SetBool ("attack", false); //agent.speed = 2; //agent.updatePosition = true; } }}


