[Solved]Physics.Raycast problem in C#

Hello,

I had made a script in javascript but now I’m translating it to C#, without any success.

This was my code in javascript:

var ray = objCam.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
//DO SOMETHING
}

This is what I have in C#:

Ray ray = objCam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (ray, hit))
{
//DO SOMETHING
}

Can anyone tell me what I’m doing wrong, because the C# part doesn’t work?!

Best Regards,
Zarillo

RaycastHit is an output parameter, so it needs the keyword ‘out’ when calling Physics.Raycast:

Physics.Raycast (ray, out hit)

Thanks for your help!