- Home /
Can someone please tell me whats wrong with my code - the error syas it expects to see ')' instead it saw 'hit' (the one after 'out')
var TheDamage: int = 50;
var Distance: float;
var MaxDistance: float = 1.5;
function update ()
{
if (input.GetButtonDown("fire1"))
{
var hit:RaycastHit;
if (Physics.Raycast (transfrom.position,Transform.TansformDirection(Vector3.hit),out hit)
{
Distance=hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage",TheDamage,SendMessageOptions.DontRequireReceiver);
}
}
}
}
it still gives me the same error,and now it also says there's an unexpected token
There is maybe a typo :
TansformDirection
Should probably be Transform or transform ... Direction
if (Physics.Raycast (transfrom.position,Transform.TansformDirection(Vector3.hit),out hit)
You have three opening parenthesis [ '(' x 3 ] but only two closing [ ')' x 2 ]
Additional errors:
TansformDirection
should be
TransformDirection
transfrom.position
should be transform.position
I think there's a few more in there too. Vector3.hit?
Well spotted, I should have seen the "transfrom", the amount of times I type that ins$$anonymous$$d of transform is unbelievable :D
Answer by robertbu · Nov 09, 2014 at 03:13 PM
You are missing a ')' at the end of line 10
'transform' is not 'transform' on line 10 (the o and r are reversed)
You need lower case 'transform' in your 'transform.TransformDirection()'. Lower case 't' is the transform for there current game object. Upper case 'Transform' is the class.
In Javascript/Unity script you don't use 'out' (line 10).
Input is 'Input' with an upper case 'I' on line 7
There is no such thing as Vector3.hit. I'm not sure what you intended here, but I replace it with Vector3.forward in the code below.
'update' should be 'Update' (thanks @MrSoad)
var TheDamage: int = 50; var Distance: float; var MaxDistance: float = 1.5;
function Update () { if (Input.GetButtonDown("fire1")) { var hit:RaycastHit; if (Physics.Raycast (transform.position,transform.TransformDirection(Vector3.forward),hit)) { Distance=hit.distance; if (Distance < MaxDistance) { hit.transform.SendMessage("ApplyDamage",TheDamage,SendMessageOptions.DontRequireReceiver); } } } }
Your answer
Follow this Question
Related Questions
Why wont my animations play? 1 Answer
Calling Vignetting JS shader from C# code 1 Answer
Animation script error 1 Answer
Talking Code 2 Answers