- Home /
The question is answered, right answer was accepted
BCE0051: Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float' !!!
hello , im doing a Ai script that when you approche to the gameObject it will start following you ( i'm sure it's a classic basic script for Pro's ;) ) but im get tree same Errors: -BCE0051: Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float'
in line 29.22 in line 36.22 and in line 42.22
pragma strict
var Distance;
var lookAtDistance : float = 25;
var attackRange : float = 15;
var animator : Animator;
var target : Transform;
var moveSpeed : float= 0;
var rotationSpeed: float = 1;
private var myTransform : Transform; //current transform data of this enemy
private var controller : CharacterController;
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
controller = GetComponent(CharacterController); // cache the CharacterController
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function Update ()
{
Distance = Vector3.Distance(target.position, transform.position);
if (Distance < lookAtDistance)
{
animator.SetBool("idle" , true);
animator.SetBool("walk" , false);
}
if (Distance > lookAtDistance)
{
animator.SetBool("idle" , true);
animator.SetBool("walk" , false);
}
if (Distance < attackRange)
{
animator.SetBool("idle" , false);
animator.SetBool("walk" , true);
}
// find the target direction:
var dir: Vector3 = target.position - myTransform.position;
dir.y = 0; // ignore height differences to avoid enemy tilting
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(dir), rotationSpeed*Time.deltaTime);
//move towards the player:
controller.SimpleMove(myTransform.forward * moveSpeed);
}
at first i thought puting float's would work on the variables but it don't please help me!!
Answer by robertbu · Apr 25, 2014 at 02:43 AM
You did not give 'Distance' a type. Change line 2:
var Distance : float;
Without implicitly or explicitly giving a variable a type, the variable will be of type 'object'. The compiler cannot compare something of type object with something of type float.
oops this was quite emberassin for me Thank you very much =D !!