Added player movement
This commit is contained in:
parent
88fb3d4cec
commit
fa8e76b3e0
|
@ -1,6 +1,3 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
@ -11,37 +8,36 @@ public class PlayerMovement : NetworkBehaviour
|
|||
[SerializeField] private NavMeshAgent _navMeshAgent;
|
||||
|
||||
private Camera _camera;
|
||||
private Mouse _mouse;
|
||||
|
||||
#region Server
|
||||
|
||||
[Command] private void CmdMove()
|
||||
[Command] private void CmdMove(Vector3 destination)
|
||||
{
|
||||
_navMeshAgent.SetDestination(new(1, 1, 1));
|
||||
_navMeshAgent.SetDestination(destination);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Client
|
||||
|
||||
[Client]
|
||||
private void OnEnable()
|
||||
{
|
||||
_camera = GetComponent<Camera>();
|
||||
_navMeshAgent = GetComponent<NavMeshAgent>();
|
||||
_camera = FindObjectOfType<Camera>();
|
||||
_mouse = Mouse.current;
|
||||
}
|
||||
|
||||
private void KDSUpdate()
|
||||
[Client]
|
||||
private void Update()
|
||||
{
|
||||
var mouse = Mouse.current;
|
||||
|
||||
if (mouse.leftButton.wasPressedThisFrame)
|
||||
if (_mouse.leftButton.wasPressedThisFrame)
|
||||
{
|
||||
RaycastHit hit;
|
||||
Ray ray = _camera.ScreenPointToRay(new(mouse.position.x, mouse.position.y, 0));
|
||||
if (Physics.Raycast(GetComponent<Camera>().transform.position,
|
||||
transform.TransformDirection(Vector3.forward), out 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))
|
||||
{
|
||||
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance,
|
||||
Color.yellow);
|
||||
Debug.Log("Did Hit");
|
||||
CmdMove(hit.point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue