Hello, I would like to know how to end my game when my player has been destroyed heres my code:

var player : GameObject;

function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.tag=="Enemy"){ 

Destroy(player);



print("hit");
 }
}

var loadLevel : string;
var mySkin : GUISkin;
var endMessage : string;
var heKillsMe : string;

function OnCollisionEnter(col : Collision)
{
    if(col.gameObject.name == heKillsMe)
    {
        Destroy(gameObject);
        iWantToSeeMessage = true;
    }
}

function OnGUI()
GUI.skin = mySkin;
{
    if(iWantToSeeMessage)
    {
        GUILayout.Window(Rect(Screen.width/2,Screen.height/2, 60,40), "The End!");
        GUILayout.Label(Rect(Screen.width/2,Screen.height/2-15,1,1), ""+endMessage);
        GUILayout.Button(Rect(Screen.width/2,Screen.height/2,50,15), "Exit Game");
        {
            Application.Quit();
        }
        GUILayout.Button(Rect(Screen.width/2+15,50,15), "Load "+loadLevel);
        {
            Application.LoadLevel(loadLevel);
        }
    }
}
  • Attach onto player
  • heKillsMe is the enemy/bullet
  • EndMessage is what will appear
  • loadLevel level to load button