hi guys, i just created a raycast script that opens a door when the hit collider hits the door. The script i made was done in java now the thing is that i now want to take this script and make the same thing in C sharp. But as soon as i tried that i came across a problem, basically in the update function in my java script i created a variable called :
var Hit: RaycastHit;
now in C sharp if i try to make the same variable it wont work what is the correct way to put this right in C#
here are my scripts :
JAVA:
var RayCastDist = 5;
function Update () {
var hit : RaycastHit;
Debug.DrawRay (transform.position, Vector3.forward * RayCastDist, Color.green);
if(Physics.Raycast(transform.position,Vector3.forward, hit, RayCastDist))
{
Debug.DrawRay (transform.position, Vector3.forward * RayCastDist, Color.red);
if(hit.collider.gameObject.tag == "door"){
hit.collider.gameObject.animation.Play("Door animation");
}
}
}
That was the Java script here is the C sharp :
using UnityEngine;
using System.Collections;
public class OpenDoorScriptRayCSharp : MonoBehaviour {
public float RayCastHitDoor = 5;
// Update is called once per frame
void Update () {
}
}
So yea thats the scripts and thanks in advance :)
You have a float defined as 5, to increase readability you could use 5.0f instead. This is common practice but a choice nonetheless. (Thanks go to KeithK for spotting the error)
– anon90873654By the way, this is actually not Java at all; rather, it’s JavaScript (more precisely, UnityScript — Unity’s adaptation of JavaScript), which is not the same thing.
– anon52402608