Melee script help

so i just started working with unity, and was watch a tutorial. i copied this script exactly from the video, but i get errors he doesnt. the script is

#pragma strict
var TheDammage : int = 50;
var distance : float;

function update ()
{
	if (Input.GetButtonDown("Fire1"))
		{
 			var HIT : RaycastHit;
  			if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))   
			{
  			Distance = Hit.distance;
  			Hit.transform.sendmessage("applyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
  			}  
  	}
}

the errors i get are “unknown identifier ‘distance’” “unknown identifier ‘Hit’” "unknown indentifier ‘hit’
i have no idea how to solve this, so thank you for your help!

1 Answer

1

Hey there, welcome to unity answers.

You declared hit variable as HIT.

var HIT : RaycastHit;

But you are trying to call Hit.

Distance = Hit.distance;

So it should be:

var Hit : RaycastHit;