I was making a simple AI script in Javascript and I got a few errors, I can’t seem to find out why, could someone help me? Here is the script:
#pragma strict
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var attackRange = 15.0;
var moveSpeed = 5.0;
var Damping = 6.0;
function Update () {
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance){
renderer.material.color = Color.yellow;
lookAt();
}
if (Distance > lookAtDistance) {
renderer.material.color = Color.green;
}
if (Distance < attackRange) {
renderer.material.color = Color.red;
Attack();
}
}
function lookAt () {
var Rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, Rotation, Time.deltaTime * Damping);
}
function Attack () {
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
and here are the three errors:
Assets/AISimple.js(13,22): BCE0051: Operator ‘<’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘float’.
Assets/AISimple.js(17,22): BCE0051: Operator ‘>’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘float’.
Assets/AISimple.js(21,22): BCE0051: Operator ‘<’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘float’.