using UnityEngine; using UnityEngine.AI; public class FollowLeader : MonoBehaviour { public GameObject leader; private NavMeshAgent agent; private Animator anim; // Start is called before the first frame update void Start() { agent = this.GetComponent(); anim = this.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); } } }