I have used ScreenPointToRay without issues before, but for some reason its not working. I must be doing something simple wrong but I cant figure it out. Here is my C# code:
Ray ray;
RaycastHit hit;
void Start()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition)
}
void Update ()
{
if(Input.GetMouseButton(1))
{
if(Physics.Raycast(ray, out hit))
{
itemScript = itemManager.GetComponent<ItemManager>();
Debug.Log("you hit " + hit.transform.name);
}
}
}
I am trying to right click on a box (with a collider, and it has no layer so its not in a layer that doesnt see raycasts) and yet all I get is “You hit terrain” , I cant ever hit the box. Argg