displaying text problem

I have made this script for my splitscreen tank game, where if the player looses all five lives their tank prefab would be disabled, I have set up a text variable for both the remaining health and lives, but for some reason when the tank runs out of lives and is disabled the text doesn’t change to 0. Has it got something to do with the disabling of the tank or is it something else?

here is the script
var spawneffect : Transform;
var deatheffect : Transform;
var SpawnPoint : Transform;
var respawn : boolean = false;
var health : float = 90;
var lives : float = 5;
var outoflives : boolean = false;
var gotlives : boolean = true;
var healthtext : UI.Text;
var livestext : UI.Text;

  function Damage(dmg:float){
 health -= dmg;
 function Update (){
 if (healthtext)healthtext.text = health.ToString();
 if (livestext)livestext.text = lives.ToString();
 if (gotlives){
 if(health <=0){

   Instantiate (deatheffect,transform.position,transform.rotation);

  transform.position = SpawnPoint.position;
    Instantiate (spawneffect,transform.position,transform.rotation);

  var audio: AudioSource = GetComponent.<AudioSource>();
  lives -= 1;
  health += 100;

 if (lives <=0){
 outoflives = true;
 gotlives = false;


From looking at your script, I would expect the text to be displaying 0 Lives and 100 Health after losing your final life.

Is this what you are seeing?

If this is what you are seeing, and you are expecting/wanting Health to also be showing 0, then in your if Health block, where you are setting Health back to 100, just change it to the code below. Currently when your health dropped to or below 0 on the final life, and it decrements lives to 0, it is also setting health to 100.


Hope this helps,