What am I allowed to put after "<"?

Hi. I found a script that makes a game object follow another game object. Now I want to make a script that makes it so that if you click your left mouse button when the object that is following you is in a 2 meter radius, it disappears. I wrote a script that works fine except that there is an error that tells me that “Operator ‘<’ cant be used with left hand side of type UnityEngine.Vector3 and a right hand side type of UnityEngine.Vector3”. This makes sense to me but my question is, what can you put after the operator to make the script work?

Here is the script:

var enemy : GameObject;

function Update(){
	if(GameObject.Find("First Person Controller").transform.position - GameObject.Find("3rd Person Controller").transform.position < Vector3(2,2,2) && Input.getButtonDown("Left Mouse")){
		Destroy (enemy);
	}
}

Thank you so much. It actually worked!

It’s not the operator that is the problem, exactly, but the type of data you are trying to use with it. Unity’s Vector representations do not know how to evaluate ‘greater than’ or ‘less than’ between each other, because it’s not actually clear what that really means.

In this case, what you probably need is the .magnitude value. This gets the total distance of the vector, instead of trying to guess from the three axes:

if (someVector.magnitude > 2)
{
    // if the vector is longer than 2 units, this code will run!
}

Also, try using Vector3.Distance- it’ll be useful here.

var FPC : GameObject;
var TPC : GameObject; // Don't use GameObject.Find inside of Update, it's just bad.

function Update()
{
    if(Vector3.Distance(FPC.transform.position, TPC.transform.position) < 2)
    {
        // Do stuff!
    }
}

In essence, < and > only work with 1-dimensional values (integers, floats), not with vectors.