- Home /
Question by
ReflexGames · Sep 19, 2014 at 06:36 PM ·
aienemytag
EnemyAI Script help
Hey guys I have a EnemyAI Script, but I always the error "Operator < Cannot be used with a left hand side of type "object" and a right hand side of type "float".
Once
And
"Operator < Cannot be used with a left hand side of type "object" and a right hand side of type "float".
Three times
Here is the script, Thanks For Your Help!
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);
}
Comment
Answer by dmg0600 · Sep 19, 2014 at 06:50 PM
The exact same script works for me. Try forcing Distance to be float so the compiler doesn't understand it as object but as float.
var Distance : float;