I’m having trouble converting the following from Javascript to C# as I do not know what to declare the following variable as:
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
if(Physics.Raycast(transform.position, fwd, out hit, rayLength))
You were just missing Vector3 at the start of fwd so C# didn’t know what it was you were trying to make. Also in C# you need to add ‘out’ before variables that will gather info from a function as far as I understand it so that is why that is before hit in the raycast.
There is actually a var keyword in C# also which uses compile time type inference.
You could rewrite the code to something like this in C#:
void Update()
{
RaycastHit hit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd,out hit, rayLength))
{
// todo
}
///.. rest of your update function
}