- Home /
Help; I have two code errors need adivce
(3,4)uce0001 ';' expected. insert a semicolon at the end. (3,5)bce0044: expecting EOF, found 'thedammage'.
Here is my script
#pragma strict
Var TheDammage : 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", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
(please Help me out)
best piece of advice is to fix your code formatting to make it readable... highlight the code section then click on the 101/010 button.
Answer by Landern · Nov 11, 2014 at 06:27 PM
You have four mistakes in your code.
The first three are the case of "var", it should be lower case.
The second is in the first parameter of Physicis.Raycast, you are passing a type instead of the transform of the object the script is attached to.
The update function has a capital U, so "function Update()"
Also always format your code, i've done it for you, i will not in the future.
#pragma strict
var TheDammage : 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", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
each enemy have different damage amount, how to calculate the hp remain??? 1 Answer
I need help with a companion!!! 2 Answers
End game then an Object is close to another object? 0 Answers
FPSMouseScript.js 1 Answer