What should I do? Disable the AI or have the AI simply be recylced and reused?

I am new to game development and I was just trying to at least make a demo or a full game of a tiny tower defense game. Anyways I was going to have some AI come out and then eventually reach their target at which they then disappear, However My script doesn't really work. What do you think I should do? I tried adding a disable script to my AI Once the AI completes the waypoints, but it doesn't work. It gives me two errors

  1. Assets/Scripts/ExampleScript.js(5,69): BCE0005: Unknown identifier: 'EvilCube'.

  2. Assets/Scripts/ExampleScript.js(21,6): BCE0019: 'EvilCube' is not a member of 'ExampleScript.

EvilCube is the enemy AI that I am trying to disable, once it has completed the waypoints

The EvilCube has successfully gone to the waypoint, but when I add the disable part it gives me several errors

Here is the Script

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 = Vector3.zero;

if(distanceToTarget == 0)

this.EvilCube.active = false;

}

else{

velocity = moveDirection.normalized * speed;

}

rigidbody.velocity = velocity;

}

Thanks for the help.

By the way, I put the script on the GameObject "EvilCube" so in INSPECTOR I see the script, plus the waypoints and how fast I can set it, etc..

I am using JavaScript

I want to simply disable the EvilCube.

If you want to disable the whole gameobject in the scene, you just use:

this.gameObject.active = false; //you actually have to type gameObject

If you wanted to disable this script, but keep the object that had this script in this scene, you would say:

this.enabled = false;

If you wanted to destroy the GameObject from the scene, you would say:

Destroy(this.gameObject);