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 :)