void Movement() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Vector3 mousePos = Input.mousePosition; if (Physics.Raycast(Camera.main.ScreenPointToRay(mousePos), out hit, Mathf.Infinity, ~IgnoreMe)) { hasAMoveCommand = true; playerNavMeshTarget = hit.point; playerNavMeshAgent.SetDestination(playerNavMeshTarget); OnMoveStart?.Invoke(playerNavMeshAgent.destination); if (hit.transform.gameObject.GetComponent <WorldInteractive>() != null) { interactedObject = hit.transform.gameObject.GetComponent <WorldInteractive>(); } } } if ((hasAMoveCommand == true) && (playerNavMeshAgent.velocity == Vector3.zero) && (!playerNavMeshAgent.pathPending)) { if (playerNavMeshAgent.remainingDistance < playerNavMeshAgent.stoppingDistance) { if ((interactedObject != null)) { //Debug.Log((playerNavMeshAgent.transform.position - interactedObject.transform.position).sqrMagnitude); interactedObject.OnInteract(); interactedObject = null; } hasAMoveCommand = false; OnMoveStopped?.Invoke(); } } }
private void OnMoveCanceled(InputAction.CallbackContext obj) { OnMoveStopped?.Invoke(); }