Physics.Raycast (420651)

Hiyah! Unity is being very stubborn with me, and insisting that I have to use the first method declaration of Physics.Raycast (static function Raycast (origin : Vector3, direction : Vector3, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers) : bool), and I’m not sure why. My code:

Ray ray = camera.ScreenPointToRay (new Vector3(mp.x,mp.y,0));
RaycastHit hit = new RaycastHit();

if (Physics.Raycast (ray, hit, 100))
{
Debug.Log(hit.distance);
}

The two errors I get:

Can anyone please help me with this?

RaycastHit is an out parameter.

–Eric

I’m not totally schooled on my syntax terminology :sweat_smile: - Could you please let me know that that means? :slight_smile:

It means you have to write “out”, unless you’re using Javascript.

–Eric

Ah! Very interesting! I’ll have to check out making functions with my own out parameters.

Thanks for the help - I’ll try that!

Works like a charm! Thanks!