I’m trying to use one of the physics.Raycast() overloads, specifically Raycast( Ray, RaycastHit, Distance, LayerMask)
void Update () {
if ( Input.GetMouseButtonDown (0) ) {
Ray ray;
RaycastHit hitInfo = new RaycastHit();
ray = Camera.main.ScreenPointToRay( Input.mousePosition );
if ( Physics.Raycast( ray, hitInfo ) ) {
destinationObject.transform.position = hitInfo.point;
}
}
}
But when I compile the compiler can’t find the correct overload. I get the errors:
- The best overloaded method match for ‘UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3)’ has some invalid arguments
- Cannot convert from ‘UnityEngine.Ray’ to ‘UnityEngine.Vector3’
Any idea why?