Get when an enemy is killed

Hey,
I am currently very new with Unity and Javascript/C#, but have some coding knowledge in LUA, so I know basic coding structure etc.

Anyways, my question is, how would I go about getting when an enemy dies and then making something happen when they do. I currently have no enemy/AI script but I’m asking this first so I can code this at the same time as my AI.

Any help is greatly appreciated, thank you.

Are you talking about some automatic shooter like a turret, for instance? If so, Unity has a nice feature: when an object is destroyed, all references to it magically become null! Let’s suppose that a turret has a trigger to detect when an enemy enters its range, and gets a reference to the enemy in the variable target like below (turret script):

private var target: Transform;

function OnTriggerEnter(other: Collider){
  // something entered the trigger:
  target = other.transform; // get its transform in target
}

function Update(){
  if (target){ // if target exists...
    transform.LookAt(target); // aim at it...
    Shoot(); // and shoot
  }
}

Notice that this script does nothing while no enemy has entered the trigger, since target is null. When an object enters the trigger, its transform is stored in target and the fire starts; when the object is destroyed, target becomes null and the fire ceases.

Strange question, maybe you should be more specific with what you want to happen?
Anyway your AI script should have death function, something like

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {
	void Update()
    {
	    if (Health <= 0)
	    {
	    	Death();
		}
    }
    
    void Death()
    {
		//adjust score code
		//instatiate particle
		//or send message to any other object
    	Destroy(gameObject);
    }   
}

Now in the Death function you can do whatever you want…