hello i’m making a 2 D game and i add life system
and its like this
every time i get my life < 0 i change scene to GAME OVER and when i return back to the level (still in game mode) i see that my life number change to 0 instead of 3 and when i die once scene changed and life number are -1 and like this
can you tell me a code to reset my life number not when i’m re spawn but when i load the scene
#pragma strict
private var isRestarting = false;
function OnTriggerEnter2D (info : Collider2D)
{
if(info.tag == "Player")
{
if(isRestarting == false)
{
Restart();
}
}
}
function Restart () {
isRestarting = true;
GetComponent.<AudioSource>().Play();
counters.deathes += 1;
counters.lifes -= 1;
yield WaitForSeconds (GetComponent.<AudioSource>().clip.length);
Application.LoadLevel(Application.loadedLevelName);
lifes.LIVES -= 1;
if(counters.lifes <= 0)
{
Application.LoadLevel("Gameover");
}
if(loadedLevelName == level)
{
lifes.LIVES = 3;
}
}