using UnityEngine; using UnityEngine.AI; namespace UnityStandardAssets.Characters.ThirdPerson { [RequireComponent(typeof(NavMeshAgent))] [RequireComponent(typeof(ThirdPersonCharacter))] public class AICharacterControl : MonoBehaviour { public Transform target; public NavMeshAgent agent { get; private set; } public ThirdPersonCharacter character { get; private set; } private void Start() { agent = GetComponentInChildren(); character = GetComponent(); agent.updateRotation = false; agent.updatePosition = true; } private void Update() { if (target != null) { agent.SetDestination(target.position); character.Move(agent.desiredVelocity, false, false); } else { character.Move(Vector3.zero, false, false); } } public void SetTarget(Transform target) { this.target = target; } } }