How do i kill an "enemy with character controller on + few child objects on"

Helor I'm trying to seek help with this question as previously i tried on various codes on destroying game objects once i collide with them, it works but not for my AI character with character controller and few childs on it. I wanted to test if the collision works for 1 hit kill before i add in GUI health textures for it.

But it seems like this script that i'm going to attach works on a small cube with box collider and with "is trigger" being ticked, but not towards my enemy. Hope someone can tell me another different way of coding it? or do i just need to tweak something else out of it?

I'm still new to Unity between and am eager to learn more from other people as well :) Thanks heaps!

Here's my code:

//var score = 0;
var explosionPrefab : GameObject;
//var explosionLife : float = 10;
var Collider = CharacterController;

function OnTriggerEnter( other : Collider ) 
{
    if (other.tag == "Player") 
    {
        //score += 5;
        print ("ENEMY BLOWN UP");
        var expPos = other.transform.position;
        var exp : GameObject = Instantiate (explosionPrefab, expPos, Quaternion.identity);
        Destroy (other.gameObject);
    }
}

Hard to tell since it could be many things. Here’s a list of what I think might be worth checking:

  • Have you double-checked the tag name, including upper/lowercase?
  • Is the enemy’s collider on the same game object as your script (not on a parent of child)?
  • Is the Is Trigger property of the enemy’s collider ticked?
  • Are both objects on Layers that are set to collide with each other in Unity’s physics settings?

Also, I think @BeB_Wir3 is quite right, once you get it to work, it will try to destroy your player, not the enemy. That last line should be GameObject.Destroy(gameObject); (or this.gameObject if you want to be more explicit about were the property comes from).