Can figure out how to make an "If Then" statement correctly

I’m trying to make a script to simply move a enemy between two points. I got the path finding down. I am trying to make the person go to one point if they are at the other. If this is entirely incorrect please tell me.

``````var target : Transform;
var target2 : Transform;
var moveSpeed : float;

function Update(){
if(Vector3(5.425738, 2.280696, 11.30184))
GetComponent(NavMeshAgent).destination = target.position;
if (Vector3(-7, 2, 11.31746))
GetComponent(NavMeshAgent).destination = target2.position;
}

function OnTriggerEnter (info : Collider) {
}
``````

if(Vector3(5.425738, 2.280696, 11.30184)) is useless. You need to check the position of the enemy. Your code does nothing.
You need to do something like this:

``````if(gameObject.transform.position == target.position)
GetComponent(NavMeshAgent).destination = anotherTarget.position;
``````

However, this might not work, since there is a little chance, that enemy will have sometimes the exact position as target. You need to implement something like threshold:

``````if(Vector3.distance(gameObject.transform.position, target.position) < minDistance)
GetComponent(NavMeshAgent).destination = anotherTarget.position;
``````

Or you can add a collider to the target spot (be sure to make it big enough) and change the current enemy target using OnCollisionEnter or OnTriggerEnter

I presume, you are a beginner, so I recommend you to see some basic tutorials, or you will struggle on everything.

It is entirely incorrect. The if-then statement is this:

``````if (condition) {
// set target 1
}
else {
// set target 2
}
``````

And what you want to do is to get the current position of your enemy and see how far it’s from the reference point where you want to turn. Right now you’re just creating a reference point but not comparing it to anything. So take the reference point (Vector3(X, X, X)) and subtract the current position of the enemy from it, and then compare the distance (Vector3.magnitude) to a reasonably small number. Comparing floats directly is not a good idea.

Lastly, hard-coding coordinates like this is a very bad practice. You’d be better off using Colliders. The same way you’re already using it for your destination, as I can see.