Physics.Raycast problem? (C#)

I was looking around for some help on writing a object-look-at-mouse script for the player character movement (I’m making a semi-top down combat game), and found this answer:
I tried to write the first example (from the top answer) out in C#, and this is what I have:

`using UnityEngine;
using System.Collections;

public class ObjectLookAtMouse : MonoBehaviour {

private Vector3 lookTarget =;

void Update () {

    Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    RaycastHit hit;
    if (Physics.Raycast(ray, hit)) {
        lookTarget = hit.point;



It seems to be alright except for the (Physics.Raycast(ray, hit)) part. It’s underlined in VS and the error is “The best overloaded method match for UnityEngine.Phsyics.Raycast(UnityEngine.ray, out UnityEngine.RayCastHit) has some invalid arguments”. I’m not very experienced in programming and I can’t work out what the problem is. Thanks in advance for any

The error message says it all; you need the out keyword for this hit value. :wink:

if (Physics.Raycast(ray, out hit))