How to destroy all gameobject.

Is it possible to destroy all the object when my game over, All i want to do is destroy all the game object in hierarchy as soon as my game get over our player(user) get died.

Try this

	public void DeleteAll(){
		foreach (GameObject o in Object.FindObjectsOfType<GameObject>()) {
			Destroy(o);
		}
	}

Rather than Destroy() your character when he dies, turn of the renderer and the collider. That way your references in other games object to the player will still be good. If you really want to delete all the active game objects you could do:

var objects = GameObject.FindObjectsOfType(GameObject);
for (o : GameObject in objects) {
    Destory(o.gameObject);
}

A simple function that calls Destroy on all active GameObjects should be sufficient.

public void DestroyAllGameObjects()
{
	GameObject[] GameObjects = (FindObjectsOfType<GameObject>() as GameObject[]);

	for (int i = 0; i < GameObjects.Length; i++)
	{
		Destroy(GameObjects*);*
  • }*
    }