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