RayCast C# problem help?

I just asked created this C# script and which places a raycast line on the player so that when i collides with the wall it will open the door. Now this works in my Java script but as soon as i tried to make it in C it gave me three errors which are :

Error 1:


Assets/_DoorScript/OpenDoorScriptRayCSharp.cs(14,78): error CS0165: Use of unassigned local variable `hit'


Error 2:


Assets/_DoorScript/OpenDoorScriptRayCSharp.cs(14,32): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit, float)' has some invalid arguments


Error 3:


Assets/_DoorScript/OpenDoorScriptRayCSharp.cs(14,32): error CS1620: Argument `#3' is missing`out' modifier


those are the three errors that i am getting here is the script :

        using UnityEngine;
       using System.Collections;

    public class OpenDoorScriptRayCSharp : MonoBehaviour {

         public float RayCastHitDoor  = 5.0f;

        // Update is called once per frame
        void Update () {

          RaycastHit hit;

          Debug.DrawRay(transform.position, Vector3.forward * RayCastHitDoor, Color.red);
            if(Physics.Raycast(transform.position , Vector3.forward, hit, RayCastHitDoor))
        {
            Debug.DrawRay(transform.position,Vector3.forward * RayCastHitDoor , Color.green);
                   if(hit.collider.gameObject.tag == "door"){

            hit.collider.gameObject.animation.Play("Door animation");   

            }

        }

         }
      }

Thanks in advance :)

The C# version of Physics.Raycast requires keyword 'out' before hit.

Read the documentation here.

if(Physics.Raycast(transform.position, Vector3.forward, out hit, RayCastHitDoor))

Basically you need to initialize the Raycast hit (error 1):

RaycastHit hit = new RaycastHit();

And then you need to use the keyword out (error 2+3):

if(Physics.Raycast(transform.position , Vector3.forward, out hit, RayCastHitDoor)){

You need to specify the "out" keyword in front of "hit" in your Physics.Raycast() argument list.

if(Physics.Raycast(transform.position, Vector3.forward, out hit, RayCastHitDoor))

I would read up a bit about C# on the MSDN

Basically, functions expecting an "out" parameter can have an uninitialized object reference sent as an argument and it's instantiation will be taken care of in the function.