Show enemy health on collision help.

Im Looking for a way to show a GUI Texture(the enemies health) upon entering a collider, then once the enemy is dead the GUITexture no longer shows.

I managed to achieve the first part on my own, but once I kill the enemy, the enemy is destroyed but the health bar is still showing on the screen.

Any help would be appreciated.

Child the GUITexture to the enemy (drag it to the enemy object) - when an object is destroyed, all its children are destroyed too.

Oh god, you’re using that horrible tornado twins script aren’t you? Info about arrays can be found here. If you’d use array here it would look something like this:

var health : Texture2D[]; 
static var lives : int = 9;
var oldLives : int = 0 //so we know lives changed if lives != oldLives

function Update() {
    if( lives != oldLives ){
        guiTexture.texture = health[lives];
        oldLives = lives;
        if( lives = 0 ){
            Destroy( gameObject.Find( "roboBearCannonMod" );
            Destroy( gameObject ) //destroy the guiText gameObject.
        }
    }
}

significantly shorter, isn’t it? ^.^

This is the health code I use for the enemy…its attached to a GUITexture.

var health8 : Texture2D; //eight lives left
var health7 : Texture2D; //seven lives left
var health6 : Texture2D; //six lives left
var health5 : Texture2D; //five lives left
var health4 : Texture2D; //four lives left
var health3 : Texture2D; //three lives left
var health2 : Texture2D; //two lives left
var health1 : Texture2D; //one lives left
var health0 : Texture2D; //no lives left

static var LIVES1 = 9;

function Update () 
{
 switch(LIVES1)
 {
	 case 9:
		 guiTexture.texture = health8;
		 break;
		 
	 case 8:
		 guiTexture.texture = health7;
		 break;	
		 
	 case 7:
		 guiTexture.texture = health6;
		 break;
		 
	 case 6:
		 guiTexture.texture = health5;
		 break;
		 
	 case 5:
		 guiTexture.texture = health4;
		 break;
		 
	 case 4:
		 guiTexture.texture = health3;
		 break;	 
		 
	 case 3:
		 guiTexture.texture = health2;
		 break;	
		 
	 case 2:
		 guiTexture.texture = health1;
		 break;
		 
	 case 1:
		 guiTexture.texture = health0;
		 Destroy(gameObject.Find("roboBearCannonMod"));  // Destroys Health Box
		 LIVES1 = 9;
		 break;
 }

}