You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
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<NavMeshAgent>(); |
|
} |
|
|
|
// 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<ClickToMove>())) |
|
{ |
|
var data = (PathFindingCmdArgs)obj.Data; |
|
|
|
hitPoint = data.hitPoint; |
|
} |
|
} |
|
}
|
|
|