Advertisement
Guest User

Health script

a guest
Aug 23rd, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var isShot : boolean;
  4. var downed : boolean;
  5. var reviveTimer : float;
  6.  
  7. var health : float;
  8. var maxHealth : float = 100;
  9. var downedHealth : float = 50;
  10.  
  11. var healthRegen : float = 1;
  12. var regenTimer : float = 5;
  13.  
  14. function Start ()
  15. {
  16.     health = maxHealth;
  17. }
  18.  
  19. function Update ()
  20. {
  21.     //If our health goes below zero, set it to zero and set downed to true
  22.     if(health <= 0) {
  23.         health = 0;
  24.         Downed();
  25.     }
  26.     //If we are downed, start the timer to get us back up and turn health regen off
  27.     if(downed) {
  28.         reviveTimer += Time.deltaTime;
  29.         healthRegen = 0;
  30.         health = downedHealth;
  31.         //If we are downed and get to zero health, we die
  32.         if(downedHealth <= 0) {
  33.             Die();
  34.         }
  35.         //If the reviveTimer is greater than or equal to 10, set it to zero and turn downed to false
  36.         if(reviveTimer >= 10) {
  37.             reviveTimer = 0;
  38.             Upped();
  39.         }
  40.     }
  41.    
  42.     //If we aren't downed, the health regen rate will be 2
  43.     else {
  44.         healthRegen = 2;
  45.     }
  46.    
  47.     //If our health is larger than 100 our health equals 100
  48.     if(health >= 100) {
  49.         health = maxHealth;
  50.     }
  51.    
  52.     //If we have less than 100 health and aren't being shot, wait 10 seconds. Then regen our health
  53.     if(health < 99) {
  54.         if(isShot == false) {
  55.             Wait();
  56.             health += healthRegen * Time.deltaTime;
  57.         }
  58.     }
  59. }
  60.  
  61. function Downed ()
  62. {
  63.     Debug.Log("Downed");
  64.     //Add downed animation here
  65.     downed = true;
  66. }
  67.  
  68. function Upped ()
  69. {
  70.     Debug.Log("Revived!");
  71.     //Add Revive animation here
  72.     downed = false;
  73. }
  74.  
  75. function Die ()
  76. {
  77.     //Destroy(gameObject);
  78.     Debug.Log("Dead");
  79. }
  80.  
  81. function Wait ()
  82. {
  83.     yield WaitForSeconds(regenTimer);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement