Restart Level

Hi

Im trying to find a way to reload the level and lose one live

i used this function
function LivesR() {
lives -= 1;
}

and Application.LoadLevel(0) in function Update when health =0 ,but doesnt work propely , it revome 1 live but when the level is loaded again lives returns to 3.

Player_H_L Script

var health : int =100;
var lives : int=3;
var firstTime:float;
var timeInertval:float = 1;


function Update () {
 if ( Time.time >  firstTime + timeInertval){
 Addhealth();}
 
 if ( health >=100){
  health = 100;}
  
 if ( health <=0){
  health = 0;
  }
 }

function SubHealth( damage : int ) {
 health -= damage;
 	}
	


function SubLives() {
 lives --;
	}

function MyHealth(){
 return lives;
}

function MyLives(){
 return health;
}

function Addhealth(){
 firstTime = Time.time;
 health+=5;
}

Thanks for help

The simplest way I can think of off the top of my head is to create an object for holding player information, in your case the life count. Create an empty object and make sure to add the script to keep it from being destroyed and a check to make sure there will be only one copy of this object. Then just make sure that in the start function of the appropriate script you find that object and take the life count from there.

Just make the lives variable static.

That way it will be shared across multiple instances of your script and will not be reset everytime.

Charabis , xangamer
thank you very much , the two methods are working .