Operator '<' cannot be used with a left hand side of type 'UnityEngine.Vector3' and a right hand side of type 'float'.

Hi, So I’m new to Unity and I’ve just been messing around when I encountered this error. I was using this script I found online to make my enemy chase my first person character. I decided to use some of my knowledge (which is not much) to edit this script, which in turn created this error. The script I was using is below:

#pragma strict

var target : Transform; //the enemy's target
var moveSpeed = 1000; //move speed
var rotationSpeed = 20; //speed of turning
private var myTransform : Transform; //current transform data of this enemy
private var controller : CharacterController;
var lookAtDistance = 25.0;
var chaseRange = 15.0;
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 ()
{	
		// find the target direction:
		var dir: Vector3 = target.position - myTransform.position;
		dir.y = 0; // ignore height differences to avoid enemy tilting
		if (dir < lookAtDistance)
		{
		//rotate to look at the player
		myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(dir), rotationSpeed*Time.deltaTime);
        if (dir < chaseRange)
        {	
			//move towards the player:
			controller.SimpleMove(myTransform.forward * moveSpeed);
		}
	}
}

The parts I added to this script were:

var lookAtDistance = 25.0;
var chaseRange = 15.0;

then

if (dir < lookAtDistance) and if (dir < chaseRange)

(their might also be some other stuff but that is all I remember)

This is in Javascript too is that bit is needed. Also, this is my first question I’ve posted on here so if their is some guideline I broke or formating issue, it would be helpful if you could inform me so I won’t do the same mistake again.

Thanks in advance

dir is a vector not a float. Looks like you want the distance between the 2 vectors so do something like this

if( Vector3.Distance( target, myTransform ) < lookATDIstance )

use this instead :
var dist = (target.position - myTransform.position).magnitude;
if (dist < lookAtDistance)
{
etc
}

karlij1, So me being a newbie at all of this stuff, I wasn’t able to get the script working using your method. I’m sure its something I did wrong and thank you for your answer.

Anyway, I was messing around again and I solved my issue. What I did is make a new variable:

var Distance : float;

Then later on in the script I added

Distance = Vector3.Distance(target.position, transform.position);

Then after that I put

if (Distance < lookAtDistance)

and did the same for the chaseRange. Before, the AI was following me where ever I was, and I wanted to limit that, so now it does using the new addition.