|
|
|
@ -1,6 +1,4 @@ |
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.AI; |
|
|
|
using UnityEngine.EventSystems; |
|
|
|
@ -8,37 +6,50 @@ using UnityEngine.EventSystems; |
|
|
|
public class PlayerMovement : MonoBehaviour |
|
|
|
{ |
|
|
|
[Header("Components")] |
|
|
|
[SerializeField] private Player player; |
|
|
|
[SerializeField] private NavMeshAgent agent; |
|
|
|
[SerializeField] private Animator animator; |
|
|
|
|
|
|
|
|
|
|
|
private float lookRotationSpeed = 8f; |
|
|
|
private bool isMoving = false; |
|
|
|
|
|
|
|
void Awake() |
|
|
|
{ |
|
|
|
agent = GetComponent<NavMeshAgent>(); |
|
|
|
animator = GetComponent<Animator>(); |
|
|
|
private bool prepareEvent = false; |
|
|
|
private Action onDestinationReached; |
|
|
|
|
|
|
|
//input = new CustomActions();
|
|
|
|
//AssignInputs();
|
|
|
|
} |
|
|
|
private Animator animator => player.Animator; |
|
|
|
|
|
|
|
public void MoveTo(Vector3 point, Action action = null) |
|
|
|
{ |
|
|
|
agent.destination = point; |
|
|
|
onDestinationReached = action; |
|
|
|
} |
|
|
|
|
|
|
|
//replace later
|
|
|
|
public void MoveToBlock(Vector3 point, Action action = null) |
|
|
|
{ |
|
|
|
InteractionManager.Instance.AddBlockReason("Moving"); |
|
|
|
MoveTo(point, () => |
|
|
|
{ |
|
|
|
action?.Invoke(); |
|
|
|
} |
|
|
|
InteractionManager.Instance.RemoveBlockReason("Moving"); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void Update() |
|
|
|
{ |
|
|
|
if (!agent.pathPending && agent.remainingDistance > agent.stoppingDistance) |
|
|
|
isMoving = !agent.pathPending && agent.remainingDistance > agent.stoppingDistance; |
|
|
|
|
|
|
|
if (isMoving) |
|
|
|
{ |
|
|
|
prepareEvent = true; |
|
|
|
FaceTarget(); |
|
|
|
} |
|
|
|
////SetAnimations();
|
|
|
|
else if (prepareEvent) |
|
|
|
{ |
|
|
|
prepareEvent = false; |
|
|
|
onDestinationReached?.Invoke(); |
|
|
|
} |
|
|
|
|
|
|
|
SetAnimations(); |
|
|
|
} |
|
|
|
|
|
|
|
private void FaceTarget() |
|
|
|
@ -55,11 +66,10 @@ public class PlayerMovement : MonoBehaviour |
|
|
|
agent.destination = transform.position; |
|
|
|
} |
|
|
|
|
|
|
|
//void SetAnimations()
|
|
|
|
//{
|
|
|
|
// if (agent.velocity == Vector3.zero)
|
|
|
|
// { animator.Play(IDLE); }
|
|
|
|
// else
|
|
|
|
// { animator.Play(WALK); }
|
|
|
|
//}
|
|
|
|
private void SetAnimations() |
|
|
|
{ |
|
|
|
if (!animator) return; |
|
|
|
|
|
|
|
animator.SetBool("Walking", agent.velocity != Vector3.zero); |
|
|
|
} |
|
|
|
} |