Destroying the object but leaving the camera

I have a game where the camera is locked onto the player. The player is destroyed upon impact with an object, and explodes. However, the game crashes as the camera is also destroyed. Is there any way I could leave the camera to view the explosion?

Destroying an object destroys all the kids. That's a really nice feature (killing a bullet also kills the con-trail, for example.) In your case, it destroys the camera. The real solution is you will naturally add a camera script, eventually. and will unchild the camera. If you don't want to do that yet, try:

// player killing itself code:
Camera.main.transform.parent=null; // unchild from player. Keeps same position in world
Destroy(gameObject); // player kills itself

If you spawn a new player, you'll need to reposition the camera:

newPlayer = Instantiate(blah, blah...)
Camera.main.transform.parent = newPlayer; // locked onto new player
// keeps old pos and facing (where last guy died,) but will now move with player

// No way camera can know to snap to correct position, so make it:
Camera.main.transform = new Vector3(0,4,-10);
// Untested. since cam is now a child, puts it relative to player: up and behind

Camera.main.transform.LookAt(newPlayer);
// Fix the angle. Camera should stay "locked" at this relative angle

Add an ifcheck to your camera code, so it will only track the player if they exist.

Pseudocode:

if ( player != null )
{
    // Do your camera 'locking' here
}

when using the destroy method make sure to dont use the camera

if(Objecttodestroy != GameObject.Find(Camera))
{
GameObject.Destroy(Objecttodestroy);
}

or in the way you are destroying your objects