How do I fix this error in my code

Please help the error says this when I save the code:

This is the code that is used can anyone help me?


You seem to not understand UnityScript syntax in defining variables. It goes like this:

var name:type = value; //with value being optional

In your script on line 3 you do this though:

var TheDamage ; int : 50;

which is just plain wrong syntax. Follow the syntax and you won’t get any errors

Another note is that the rest of your program won’t compile either and give you a whole ton of other errors:

function update() (
{if (Input.GetButtonDown("Fire1")
    {var hit:RaycastHit;
        if (Physics.Raycast(/*etc*/));
        (Distance = hit.distance;

If you write this in a more readable format you get:

function update() ({
    if (Input.GetButtonDown("Fire1") {
        var hit:RaycastHit;
        if (Physics.Raycast(/*etc*/)); {
            Distance = hit.distance;

I’m sure you can figure out what you did wrong there. Just to make it a little easier, I’ll make a check list for you:

-2x random ( or ) that shouldn’t be there
-1x missing ( or )
-2x missing { or }
-1x random ; that shouldn’t be there

Hope this helps,

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

function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransofmDirection(Vector3.forward), hit));

Distance = hit.distance;
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);