how to ignore something for a collider

Basically what I am doing is in my game if my character walks on a box he triggers an enemy to move across the screen. Problem is that if I kill the enemy and walk on that object again I get an error saying that the gameobject is destroyed and unity basically cannot call it. how do I tell unity to ignore this if the game object is destroyed?:stuck_out_tongue:

Enemy Script

var speed : float=5.0;
var lifeTime = 3.0;
var health = 100;
var domove : int = 0;


function Awake () //unity predifined function
{
//Destroy (gameObject, lifeTime);//delete fireballs in "lifetime"/time set can also be changed from unity

}
function applydamage(damage:int)
{
Debug.Log("in applydamage"+health);
 health = health-damage;
if (health ==0)
	{
		Destroy(gameObject);
		Debug.Log("newhealthis" +health);
	}
}

function Update()
{
	if (domove==1) 
	{
		transform.Translate(Vector3(0,0,speed)*Time.deltaTime);
		//Debug.Log("update");
		animation.Play("soldier_run");
		/*audio.clip = walk;
		audio.Play("runbitch");*/
	}
}

function move () {
if (health >=1)
domove =1;
else 
domove=0;


//transform.Translate(Vector3(0,0,speed)*Time.deltaTime);
//animation.Play("soldier_run");

}

Box trigger code:

#pragma strict
var speed : float=5.0;
var enemy : GameObject;
var walk : AudioClip;

function Start()
{
	Debug.Log("start");
	enemy =  GameObject.FindWithTag("enemy");
	Debug.Log("enemy is" + enemy.tag);	
	//Debug.Log(GameObject.Find
	//enemy.SendMessage("move");
}

function OnTriggerEnter(other : Collider)
{
	if(enemy)
	Debug.Log("ouch");
	
	//enemy = GameObject.Find("swat");
	//Debug.Log("enemy is" + enemy.ToString);

	enemy.SendMessage("move",SendMessageOptions.DontRequireReceiver);
	
	
	audio.clip = walk;
	audio.Play();
	//GameObject.Find("swat").SendMessage("move");

	//Debug.Log(enemy.ToString);
	//enemy.
	//enemy.transform.Translate(Vector3(0,0,(speed*Time.deltaTime)));
	

		/*{
		enemy.transform.Translate(Vector3(0,0,(speed*Time.deltaTime)));
		//animation.Play("soldier_run");
	}*/
}

Dunno if I need to further explain the scenario if so please ask and I will inform:)

Move the findwithtag to ontriggerenter and then use the enemy value to determine if it found an enemy this time.

You don’t gain any performance increase by putting the find in Start/Awake because it’s only done when it’s needed, and not every frame. Update and FixedUpdate can benefit from cacheing the value like this.

Its because you are destroying your only enemy once his health is down.

What you need to do is change your code so that the trigger event spawns a new enemy and tells him to attack (look at Instantiate), rather than sending the enemy you have already in the scene.

Alternatively, you could change the enemy code so that it doesnt destroy, it just repositions the enemy back to his start point and sets domove to false. This method you can only have one enemy though.