I want to hit a mesh with a raycast and get the mouse/screen coordinates of where the hit occurred.
public class GetCoordinates: MonoBehaviour {
private GameObject _objectToHit;
private RaycastHit hit;
private Collider coll;
private Ray ray;
private float hitDistance = 200f;
void Start()
{
coll = GetComponent<Collider>();
_objectToHit = GameObject.Find("Street");
}
void Update()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (coll.Raycast(ray, out hit, hitDistance))
{
Debug.Log(hit.point);
}
}
}
Also I am not sure where to add the script, to the object being hit or to the camera?
RAYCASTALL
. You can very easily find a HUGE number of QA and tutorials on this. - Fattie