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 Mirror;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.AI;
|
using UnityEngine.AI;
|
||||||
|
@ -11,37 +8,36 @@ public class PlayerMovement : NetworkBehaviour
|
||||||
[SerializeField] private NavMeshAgent _navMeshAgent;
|
[SerializeField] private NavMeshAgent _navMeshAgent;
|
||||||
|
|
||||||
private Camera _camera;
|
private Camera _camera;
|
||||||
|
private Mouse _mouse;
|
||||||
|
|
||||||
#region Server
|
#region Server
|
||||||
|
|
||||||
[Command] private void CmdMove()
|
[Command] private void CmdMove(Vector3 destination)
|
||||||
{
|
{
|
||||||
_navMeshAgent.SetDestination(new(1, 1, 1));
|
_navMeshAgent.SetDestination(destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Client
|
#region Client
|
||||||
|
|
||||||
|
[Client]
|
||||||
private void OnEnable()
|
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.value, _mouse.position.y.value, 0));
|
||||||
Ray ray = _camera.ScreenPointToRay(new(mouse.position.x, mouse.position.y, 0));
|
if (Physics.Raycast(ray.origin, ray.direction, out RaycastHit hit, Mathf.Infinity))
|
||||||
if (Physics.Raycast(GetComponent<Camera>().transform.position,
|
|
||||||
transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
|
|
||||||
{
|
{
|
||||||
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance,
|
CmdMove(hit.point);
|
||||||
Color.yellow);
|
|
||||||
Debug.Log("Did Hit");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue