using UnityEngine; using UnityEngine.AI; public class FollowLeader : MonoBehaviour { public GameObject leader; private NavMeshAgent agent; private Animator anim; //private Animator animLeader; // Start is called before the first frame update void Start() { agent = this.GetComponent(); anim = this.GetComponent(); //animLeader = leader.GetComponent(); } // Update is called once per frame void Update() { Vector3 leaderPos = leader.gameObject.transform.position; agent.SetDestination(leaderPos); if (agent.remainingDistance <= agent.stoppingDistance) { anim.SetBool("isWalking", false); anim.SetBool("isIdle", true); } if (agent.remainingDistance > agent.stoppingDistance) { anim.SetBool("isWalking", true); anim.SetBool("isIdle", false); } //if (!agent.pathPending) //{ // if (agent.remainingDistance <= agent.stoppingDistance) // { // if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) // { // anim.SetBool("isWalking", false); // anim.SetBool("isIdle", true); // } // } //} //if (agent.pathPending) //{ // if (agent.remainingDistance > agent.stoppingDistance) // { // if (agent.hasPath || agent.velocity.sqrMagnitude != 0f) // { // anim.SetBool("isWalking", true); // anim.SetBool("isIdle", false); // } // } //} } }