I have been working to create mouse-based movement for my Unity3D game. I have gotten the movement, but I am having trouble setting of a variable for move speed that I can modify using a skill. This is my first attempt at using C# and I am very inexperienced. This is the beginnings of a long project, so any help or advice would be greatly appreciated.
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.AI;
namespace EO.ARPGInput
{
[RequireComponent(typeof(NavMeshAgent))]
public class PlayerController : MonoBehaviour
{
public Vector3 velocity;
[SerializeField] private InputAction movement = new InputAction();
[SerializeField] public LayerMask layerMask = new LayerMask();
private NavMeshAgent agent = null;
private Camera cam = null;
private void Start()
{
cam = Camera.main;
agent = GetComponent<NavMeshAgent>();
}
private void OnEnable()
{
movement.Enable();
}
private void OnDisable()
{
movement.Disable();
}
private void Update()
{
HandleInput();
}
public void HandleInput()
{
if (movement.ReadValue<float>() == 1)
{
Ray ray = cam.ScreenPointToRay(Mouse.current.position.ReadValue());
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100, layerMask))
{
PlayerMove(hit.point);
}
}
}
public void PlayerMove(Vector3 location)
{
agent.SetDestination(location);
}
}
}