I have a pretty simple script: The user clicks on the screen and I raycast from the point that they click at and report back. Its meant to mimic a touch-based interface.
My problem is that while it happily casts a ray, it seems to ignore my distance parameter. As a result, there are a whole mess of objects I literally can’t hit, no matter what I change my distance to. Code is below- I feel like I’m missing something obvious.
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Debug.Log(“Firing Ray”);
Debug.DrawRay(ray.origin, ray.direction * rayDistance, Color.yellow);
if (Physics.Raycast(ray, out hit,rayDistance,collectiblesLayer)){ //distance not working!
Debug.Log ("Hit something: " + hit.transform.name);
Debug.DrawLine (Camera.main.transform.position, hit.point, Color.red);
checkHit(hit.transform.gameObject);
}