Unity BCE0023 Error 'No appropriate version of 'UnityEngine.Transform.TransformDirection' for the argument list 'UnityEngine.Vector3, UnityEngine.RaycastHit)'was found.'

Hi
I’m new to Unity and I’m making a game with combat as seen in the Brackeys series ‘Create a 3D Survival Game’ and I got this text

#pragma strict

var TheDamage : int = 50;
var Distance : float;

function Update ()
{
if (Input.GetButtonDown(“Fire!”))
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward, hit))
)
Distance = hit.distance;
hit.transform.SendMessage(“ApplyDamage”, TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
Please help!

You should format your code using the 101010 button.

After doing this I found some brackets in odd places, moved these and saved into my project with no errors. Weather it does exactly what you want it to do is a different matter and a different question…

Here is your code, reformatted and potentially fixed :

#pragma strict

var TheDamage : int = 50;
var Distance : float;

function Update() { 

    if (Input.GetButtonDown("Fire!")) { 
    
        var hit : RaycastHit;

        if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit)) {
            Distance = hit.distance; 
            hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
        }
    }
}