Edits to player movemend after finishing lecture

This commit is contained in:
Stedd 2023-09-03 15:07:15 +02:00
parent fa8e76b3e0
commit edc946e6ef
2 changed files with 14 additions and 11 deletions

View File

@ -21,24 +21,23 @@ public class PlayerMovement : NetworkBehaviour
#region Client
[Client]
private void OnEnable()
public override void OnStartAuthority()
{
_navMeshAgent = GetComponent<NavMeshAgent>();
_camera = FindObjectOfType<Camera>();
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);
}
}

View File

@ -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}