- Home /
 
How can I get my Lives scripts working
hey Im having trouble getting my Life system working my respawn works fine but I cant get my lives removed when I die. Heres my code its pretty long so I edited it only to show the life parts any help would be much appreciated.
Respawn Code
public class Respawn : MonoBehaviour
 
                
                
               {
public HealthControl Health;
 
               public void OnTriggerEnter(Collider other) { //Remove Life if (other.tag == "Player")
 
                {
     Invoke("RemoveLife", respawnTime);
     //guiTexture("LIVES");
 }
  
               public void RemoveLife() { Health.RemoveLife(); invokeToggle = false; } 
}
Lives Code
public class HealthControl : MonoBehaviour
 
                
                
               {
Texture2D Life1; //One Life Left Texture2D Life2; //Two Lives Texture2D Life3; //Full Health
 
               static int Health = 3;
 
               void Update() { switch (Health) { case 3: guiTexture.texture = Life1; break;
 
                    case 2:
        guiTexture.texture = Life2;
        break;
     case 1:
        guiTexture.texture = Life1;
        break;
 }
 
               }
  
               public void RemoveLife() { if (Health < 1) { Application.LoadLevel(4); } } 
}
Im just not sure how to get the HealthControl code to load the GUI textures when I need them
Answer by Mike 3 · Jun 15, 2010 at 04:07 PM
Something like this would do it:
public class HealthControl : MonoBehaviour { public Texture2D Life1; //One Life Left public Texture2D Life2; //Two Lives public Texture2D Life3; //Full Health
 
                static int Health = 3;
 public void RemoveLife()
 {
     --Health;
     if (Health < 1)
     {
         Application.LoadLevel(4);
     }
     switch (Health)
     {
         case 3:
         guiTexture.texture = Life3;
         break;
         case 2:
         guiTexture.texture = Life2;
         break;
         case 1:
         guiTexture.texture = Life1;
         break;
     }
 }
 
               } 
 
              If it works pls mark the question as resolved by accepting this answer.
Your answer