OnDelete?

How could I make something like on delete. So if the object is being deleted thena script on it uses on delete and executes some code, is that possible? The script needs to be on the object thats being deleted.

void OnDestroy() 
{

}

Ok, I want to detach the main camera from the object when its destroyed but it doesnt seam to work. The main camera is a child of the object with the on destroy script. I just dont wnat the main camera to be destroyed with the player.

function OnDestroy() {

Camera.main.transform.parent = null;

}

Why don’t you try a script to make your camera smoothly follow a “target” (your player) so its not attached to the player. You will of course need to remember to put a check in the camera script not to run if the target/player is null.

I tried doing smooth but I wasnt sure what to do. I know how to make it follow but its pretty jerky. Its used as a first person camera.