From edc946e6efacd0a50f2125dd6e00ccafa7f52ce2 Mon Sep 17 00:00:00 2001 From: Stedd Date: Sun, 3 Sep 2023 15:07:15 +0200 Subject: [PATCH] Edits to player movemend after finishing lecture --- Assets/PlayerMovement.cs | 21 ++++++++++----------- Assets/Prefabs/Player.prefab | 4 ++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Assets/PlayerMovement.cs b/Assets/PlayerMovement.cs index b06f763..c3898a4 100644 --- a/Assets/PlayerMovement.cs +++ b/Assets/PlayerMovement.cs @@ -21,24 +21,23 @@ public class PlayerMovement : NetworkBehaviour #region Client - [Client] - private void OnEnable() + public override void OnStartAuthority() { - _navMeshAgent = GetComponent(); - _camera = FindObjectOfType(); + base.OnStartAuthority(); + _camera = Camera.main; _mouse = Mouse.current; } - [Client] + [ClientCallback] private void Update() { - if (_mouse.leftButton.wasPressedThisFrame) + if (!isOwned) return; + if (!_mouse.leftButton.wasPressedThisFrame) return; + Ray ray = _camera.ScreenPointToRay(new(_mouse.position.x.value, _mouse.position.y.value, 0)); + + if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity)) { - Ray ray = _camera.ScreenPointToRay(new(_mouse.position.x.value, _mouse.position.y.value, 0)); - if (Physics.Raycast(ray.origin, ray.direction, out RaycastHit hit, Mathf.Infinity)) - { - CmdMove(hit.point); - } + CmdMove(hit.point); } } diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 8bef261..5e0f04e 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -418,3 +418,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: dc5d69536d0782647a3de12f2d524c45, type: 3} m_Name: m_EditorClassIdentifier: + syncDirection: 0 + syncMode: 0 + syncInterval: 0 + _navMeshAgent: {fileID: 6135570535502036925}