Adding Distance in javascript

How can i add distance into a javascript? I'm trying to make an AI script and below is the part which involves distance

var moveSpeed = 3.0;

//Transform Variables
var Target : Transform;
var bulletPrefab : Transform;
var dead : Transform;

var attackRange = 30.0;

function Attack ()
   var distance = Vector3.Distance(transform.position, Target.position); 

   if(distance > attackRange)

Your script should work, except I think you might have meant to test for 'less than' instead of 'greater than'.


if ( distance <= attackRange )
// attack the enemy, because you're within range

Try separating the variable and the calculation for the distance:

var distance : float;
distance = Vector3.Distance( transform.position, target.position );
//Also, be sure to name your variables in lower camelCase