Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.AI;
- using UnityEngine;
- [RequireComponent(typeof(NavMeshAgent))]
- public class AIMover : MonoBehaviour, IAction
- {
- public NavMeshAgent agent;
- public PatrolPath path;
- private int pathIndex;
- public float arriveDistance = 1.5f;
- private void Start()
- {
- SetDestination(path.GetWayPoint(pathIndex));
- }
- public void SetDestination(Vector3 point)
- {
- GetComponent<ActionScheduler>().StartAction(this);
- agent.isStopped = false;
- agent.SetDestination(point);
- }
- private void Update()
- {
- float distance = Vector3.Distance(transform.position, agent.destination);
- if (distance < arriveDistance)
- {
- pathIndex = path.GetNextIndex(pathIndex);
- SetDestination(path.GetWayPoint(pathIndex));
- }
- }
- public void Cancel()
- {
- agent.isStopped = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement