How do I create a simply disable script for enemy AI once it completes its waypoints?

I have looked around at least three days now and I can't seem to find anything about incorporating a disable script along side a waypoint script.

Essentially I want the AI to become disabled as soon as it has finished its last waypoint. How would I begin to do this? Below is the script.


EDIT-> I have changed the original script to support the ones the people who have answered my question. Thanks!

var waypoint : Transform;

var speed : float = 20;

var distanceToTarget : float = Vector3.Distance(transform.position, EvilCube);

function Update() {

var target : Vector3 = waypoint.position;

var moveDirection : Vector3 = target - transform.position;

var velocity = rigidbody.velocity;

if(moveDirection.magnitude < 1){

velocity =;

if(distanceToTarget == 0) = false;



velocity = moveDirection.normalized * speed;


rigidbody.velocity = velocity;


calculate the distance between this object and the waypoint position (in your script, "target"), using Vector3.Distance:

var distanceToTarget : float = Vector3.Distance(transform.position, target);

Then check if the distance is zero, which would mean you reached the target, and disable the gameobject:

if(distanceToTarget == 0) = false;

I would put a variable in there and name it "waypointReached", make it a boolean. start of with it's boolean false, then once it has reaches the waypoint change it to true. then add code, where if waypointReached is true, destroy the object. Hope that helps some.