Scripts Destroys all Objects its Attached to!

Alright as of now Im trying to make it so when I jump on a characters head it destroys the character and all it children. That is working perfectly. The only problem is when I have multiples of these enemys and I land on one of their heads it destroys every enemy that has the script attached. Now here is my code so far.

var children : GameObject[];

function Update () 
{
    if (Fallout.enemyisDead)
    {
        DestroyAll();
    }
}

function DestroyAll()
{
    for(var child in children)
        Destroy(child);
}

That causes every enemy with the script attached to "die" or get destroyed. Please help

Thank you in advance.

Hey Mr. Waffle,

=D

You might have a specific reason for destroying the children that way and if you do disregard my advice. But if you Destroy a parent object, all of the children will be destroyed with it. So all you should have to do is (in a script attached to the parent):

function KillThisGuy()
{
  //using this will specifically destroy the GameObject attached to this script along with any children.
  Destroy(this.gameObject);
}

This method works for me. Hopefully it is what you are looking for.

edit...

///var children : GameObject[];

function Update () 
{
    ///make sure what ever is controlling this condition is only effecting this local instance
    if (Fallout.enemyisDead)
    {
        DestroyThisGameObject();
    }
}

function DestroyThisGameObject()
{
    //using this will specifically destroy the GameObject attached to this script along with any children.
  Destroy(this.gameObject);
}

create another script and attach it to the enemies head. You can now set a variable in here to determine which enemy you are killing. Like this

var myHeadWasHit : boolean;

function Start()
{
  myHeadWasHit = false;
}

Now back to your trigger.

OnTriggerEnter (other : Collider)
{ 

    if(other.gameObject.name == "head") 
    { 

        other.GetComponent("nameOfScriptAttachedToHead").myHeadWasHit = true; 

    }

} 

Now you can check that variable in your enemyScript

function Update () 
    {
        ///make sure what ever is controlling this condition is only effecting this local instance
        if (transform.Find("whatEverYouNamedYourHeadGameObject").GetComponent("nameOfScriptAttachedToHead").myHeadWasHit == true)
        {
            DestroyThisGameObject();
        }
    }

For anyone wondering this is what I cam up to be my final solution

var enemyisDead;

function DestroyThisGameObject()
{
    Destroy(this.gameObject);
}

function OnTriggerEnter (other : Collider)
{
    if(other.gameObject.name == "Player")
    {
        DestroyThisGameObject();
    }
}