Reset The scripts!

When I play my game and lose all my lives I get a GameOver but I know when I click play again all the other scripts are still running and I have already lost my health and it just brings me back to GameOver. So how do I make scripts reset so I can have full health again?

This Is the code Im going to put the reset part into when I click play

var isInstructionButton = false; 
function OnMouseEnter() 
{
//change the color of the text
renderer.material.color = Color.green;
}

function OnMouseExit() 
{
//change the color of the text
renderer.material.color = Color.white;
}

function OnMouseUp()
{

if (isInstructionButton)
{
 Application.LoadLevel(6);
}

else
{
//Load game
Application.LoadLevel(1);
(insert reset info here)
}
}

Hello anyone there???

Hmm… I think you should reset all your variables in the Start() function of whatever scripts you happen to have. That should set them all to their default values whenever the script if initialized, which should be when the level is loaded. I say should, though.

Hello there LuckyDog, I was developing a game where the same thing happened. There is an easy fix that solves this. Basically whenever you que teh game over you have to type in somthing like this…

else
{
//Load game
playerscript.playerlives = #;
Application.LoadLevel(1);
(insert reset info here)
}
}

so basically you tell the scripts to tell the other scripts to but your player lives/hp or whatever, to the # you want it to. Make sure that your var for playerlives is static so it can be accessed in other scripts.

Make sure in your hierarchy you have a root game object that all of your other gameobject sits underneath.

For every script that has level specific information that needs to be reset make sure you add a

void Restart()
{
 health = 100;
 lives = 2;
// etc etc

}

Then use this to fire all the Restart procedures:

myLevelsRoot.BroadcastMessage("Restart");