For this project I want to make it work with the new input system as I go along so I created an input action asset and created this script for my unit object. T
public class InputReader : MonoBehaviour
{
PlayerControls playerControls;
private void OnEnable()
{
playerControls.Enable();
}
private void OnDisable()
{
playerControls.Disable();
}
private void Start()
{
playerControls = new PlayerControls();
playerControls.Enable();
}
public Vector2 GetMousePosition()
{
return playerControls.Player.Point.ReadValue<Vector2>();
}
}
Then, in my Mouse World script I created a refence to my input reader and used it in the ScreenPointToRay() function.
Ray ray = Camera.main.ScreenPointToRay(inputReaderLink.GetMousePosition());
Debug.Log(Physics.Raycast(ray));