using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; using AX.MessageSystem; using System; using AX.InputSystem; [RequireComponent(typeof(NavMeshAgent))] public class ClickToMove : MonoBehaviour { private NavMeshAgent m_Agent; private Vector3 hitPoint = Vector3.zero; // Use this for initialization void Start () { m_Agent = GetComponent(); } // Update is called once per frame void Update () { if (hitPoint != Vector3.zero) { m_Agent.destination = hitPoint; } } void OnEnable() { MessageDispatcher.AddListener("PATH_FINDING_COMMAND", PathFinding); } void OnDisable() { MessageDispatcher.RemoveListener("PATH_FINDING_COMMAND", PathFinding); } void OnDestroy() { MessageDispatcher.RemoveListener("PATH_FINDING_COMMAND", PathFinding); } private void PathFinding(IMessage obj) { if (SelectedObjs.selectedCharacters.Contains(gameObject) || (SelectedObjs.selectedObj == gameObject && SelectedObjs.selectedObj.GetComponent())) { var data = (PathFindingCmdArgs)obj.Data; hitPoint = data.hitPoint; } } }