Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EnemyAI : MonoBehaviour
- {
- public UnityEngine.AI.NavMeshAgent agent { get; private set; } // the navmesh agent required for the path finding
- public ThirdPersonCharacter character { get; private set; } // the character we are controlling
- public Transform target; // target to aim for
- public float dangerRadius = 5f;
- private void Start()
- {
- // get the components on the object we need ( should not be null due to require component so no need to check )
- agent = GetComponentInChildren<UnityEngine.AI.NavMeshAgent>();
- character = GetComponent<ThirdPersonCharacter>();
- agent.updateRotation = false;
- agent.updatePosition = true;
- }
- private void Update()
- {
- if (target != null)
- agent.SetDestination(target.position);
- if (agent.remainingDistance < dangerRadius)
- {
- agent.isStopped = false;
- character.Move(agent.desiredVelocity, false, false);
- }
- else
- {
- character.Move(Vector3.zero, false, false);
- agent.isStopped = true;
- }
- if (agent.remainingDistance < 1f)
- {
- //maybe call attack animation, or scream animation
- Debug.Log("you died bro");
- }
- }
- public void SetTarget(Transform target)
- {
- this.target = target;
- }
- }
- }
Add Comment
Please, Sign In to add comment