Restart the game when Health variable reaches 0

This is the script I am using.
I did not make this script!
Basicly, I want the game to restart when the health reaches 0.
I have very little scripting experience, but am happy to learn.
Anyone know how I might be able to achieve this?

@script ExecuteInEditMode()
var healthTexture : Texture2D;
var healthBorder : Texture2D;
var health : int = 100;

function OnGUI () {
	
	// At first we draw border/background texture (with current texture it isn't important)
	GUI.DrawTexture(Rect(43,Screen.height - 65,314,36), healthBorder);

	//Now on top we can put Health Bar texture
	var adjust : int = health * 3;                       //adjusting texture size (width) / health(100)
	GUI.BeginGroup(Rect(55,Screen.height - 55,adjust,15));
	GUI.DrawTexture(Rect(0,0,290,15), healthTexture);
	GUI.EndGroup();
}

void Update()
{
if(health <= 0)
{
Application.LoadLevel(/here write number of the level (or name of the level) which you want to load/)
}
}

Enjoy…Cheers…IF found useful then don’t forget to mark the answer…

Do you want to restart the current level, or start over from the beginning?

Use Application.LoadLevel(“Level”), where ‘Level’ is the name or index of the level you want to load (if you use the index, don’t use quotation marks). If you want to restart the current level, you can write Application.LoadLevel(Application.loadedLevel).

Why not simply add an Update() function that checks if the health is below 0 and runs Application.LoadLevel() accordingly?

Here is the full code:

@script ExecuteInEditMode()
var healthTexture : Texture2D;
var healthBorder : Texture2D;
var health : int = 100;

function OnGUI () {

    // At first we draw border/background texture (with current texture it isn't important)
    GUI.DrawTexture(Rect(43,Screen.height - 65,314,36), healthBorder);

    //Now on top we can put Health Bar texture
    var adjust : int = health * 3;                       //adjusting texture size (width) / health(100)
    GUI.BeginGroup(Rect(55,Screen.height - 55,adjust,15));
    GUI.DrawTexture(Rect(0,0,290,15), healthTexture);
    GUI.EndGroup();
}

function Update () {
	if(health<0){
		Debug.Log("Player is dead");
	        Application.LoadLevel("Your scene");
	}
}

Hope this helps!

Before loading the level it’d be nice to give the player some time to realize what just happened. For that you could create a simple timer:

float restartTimer;
bool gameOver = false; //changing this to a more general "game state" later on will give more control
void Update()
{
    if (health < 0 && !gameOver)
    {
        //happens once, as state changes to game over
        restartTimer = 4.0f;
        gameOver = true;
    }

    if (gameOver)
    {
        gameTimer -= Time.deltaTime; //count down when in gameOver state
        if (gameTimer < 0.0f) //add '&& Input.GetButtonDown("Fire1")' to allow user to choose when to restart, but stops them accidentally clicking and missing a game over message
        {
            Application.LoadLevel(Application.loadedLevel); //or whatever level you want
            //update the state so LevelLoad doesn't keep being called. Probably not needed if this script gets destroyed anyway
            gameOver = false;
            health = 100;
        }
    }
}

... then later in your OnGUI

    if (gameOver)
    {
        //draw game over message
    }

... Don't forget to disable some player controls so you can't keep playing when in the gameOver state

There may be other timing methods (I’m not a fan of the yield method) but this should work.