Melee Script Help

Assets/MeleeSystem.js(13,18): BCE0044: expecting :, found ‘=’.
Is the error I get . I have went through and done what it asks only to be in a slew of other errors

Here is my script.

#pragma strict

var Damage : int = 25;
var Distance : float;

function Update ()
{
   if (Input.GetButtonDown("Fire1"))
   {
      var hit : RaycastHit;
      if (Physics.Raycast (transform.position, transform.forward, hit))
      (
       {Distance = hit.distance;
         hit.transform.SendMessage("ApplyDamage"), Damage, SendMessageOptions.DontRequireReceiver);
      }
}   

;

1 Answer

1

In line 12 you have a bracket “(”, remove it. Also you should remove the semicolon at the very end of your file (line 18)

You should also tidy up your indention. In line 13 you should place the “Distance = …” in a new line.

Variable names usually start with a lowercase letter.

ps: you’re also missing the closing bracket of your Update function.

Basically something like this:

#pragma strict
 
var damage : int = 25;
var distance : float;
 
function Update ()
{
    if (Input.GetButtonDown("Fire1"))
    {
        var hit : RaycastHit;
        if (Physics.Raycast (transform.position, transform.forward, hit))
        {
            distance = hit.distance;
            hit.transform.SendMessage("ApplyDamage"), damage, SendMessageOptions.DontRequireReceiver);
        }
    }
}

Nevermind I was stupid and didn't copy it right. Im very sorry for my lack of knowledge for these things. Im now going to tackle learning these things. Thank you for your help you have no idea what it means !

–

Its simple syntax... When I look at your script I'm thinking c# writer in a java script!

–

Thats nice

–