LoadLevel Health Question.

OK so i use those two script you can see below for my player’s hearts. How is it possible to make the hearts be minus 1 when i press the Respawn button and the level is loaded? Also, i noticed that some objects that were destroyed at first, were loaded together with the level and i dont really want that. Thanks!

FallDamage.js

var hearts : int = 3;

function OnGUI(){
	GUI.Box(new Rect(20,20,100,40), "Hearts : " + hearts);
	
	if(hearts < 0){
		hearts = 0;
	}		
}

TriggerFloor.js

var showGUI : boolean = false;

function OnTriggerEnter(other:Collider){
	var otherScript : FallDamage = GameObject.Find("Player").GetComponent(FallDamage);
	otherScript.hearts -= 1;
	
	if(other.gameObject.name == "Player"){
		showGUI = true;
	}	
}

function OnGUI(){
	if(showGUI){
		if(GUI.Button(new Rect(20,70,100,50), "Respawn")){
			Application.LoadLevel(Application.loadedLevel);
		}	
	}
}

Maybe you want to avoid to reload the whole level since it seems you only want to respawn your player.

So you would have:

function OnGUI(){
  if(showGUI){
    if(GUI.Button(new Rect(20,70,100,50), "Respawn")){
       transform.position = originalPosition;
       hearts = -1;
    }
   }
}

Now if you really want to reload you could have a Start

function Start(){
   hearts = -1;
}

then you can use DontDestroyOnLoad to save some object from destruction: