diff --git a/Assets/GameAssets/Prefabs/Network/Player.prefab.meta b/Assets/GameAssets/Prefabs/Network/Player.prefab.meta new file mode 100644 index 0000000..7a2327f --- /dev/null +++ b/Assets/GameAssets/Prefabs/Network/Player.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: ea740d57598a4f44b87d8a273e3e0687 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameAssets/Scripts/PlayerMovement.cs b/Assets/GameAssets/Scripts/PlayerMovement.cs index c7d27bb..52b250f 100644 --- a/Assets/GameAssets/Scripts/PlayerMovement.cs +++ b/Assets/GameAssets/Scripts/PlayerMovement.cs @@ -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(); - animator = GetComponent(); + 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; - - //replace later - action?.Invoke(); + onDestinationReached = action; } + 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); + } } \ No newline at end of file