- Home /
The question is answered, right answer was accepted
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!
Your fire axis really has an exclamation point on the end of its name???
@$$anonymous$$rSoad Thanks! It worked! :D @Jeff $$anonymous$$esselman yeah, I think I was thinking of The I.T. Crowd at that point, so I think I put 'Fire!' ins$$anonymous$$d of 'Fire1'
Answer by MrSoad · Nov 18, 2014 at 07:41 PM
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);
}
}
}