Before updating to Windows 10 you may need to return your Pro license. More information here

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;



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.

more ▼

asked Jan 03, 2011 at 09:09 PM

avatar image

25 24 21 29

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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:

more ▼

answered Jan 03, 2011 at 09:20 PM

avatar image

3.6k 168 139 191

Sorry for spamming. I just needed to know all the details. Thanks for helping me. +1 for the help.

Jan 03, 2011 at 09:23 PM Didymos

Well I read your answer and I decided to apply the first part "this.gameObject.active = false" and it worked. Best Answer.

Jan 03, 2011 at 09:30 PM Didymos
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 03, 2011 at 09:09 PM

Seen: 1289 times

Last Updated: Jan 03, 2011 at 09:09 PM