Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- var isShot : boolean;
- var downed : boolean;
- var reviveTimer : float;
- var health : float;
- var maxHealth : float = 100;
- var downedHealth : float = 50;
- var healthRegen : float = 1;
- var regenTimer : float = 5;
- function Start ()
- {
- health = maxHealth;
- }
- function Update ()
- {
- //If our health goes below zero, set it to zero and set downed to true
- if(health <= 0) {
- health = 0;
- Downed();
- }
- //If we are downed, start the timer to get us back up and turn health regen off
- if(downed) {
- reviveTimer += Time.deltaTime;
- healthRegen = 0;
- health = downedHealth;
- //If we are downed and get to zero health, we die
- if(downedHealth <= 0) {
- Die();
- }
- //If the reviveTimer is greater than or equal to 10, set it to zero and turn downed to false
- if(reviveTimer >= 10) {
- reviveTimer = 0;
- Upped();
- }
- }
- //If we aren't downed, the health regen rate will be 2
- else {
- healthRegen = 2;
- }
- //If our health is larger than 100 our health equals 100
- if(health >= 100) {
- health = maxHealth;
- }
- //If we have less than 100 health and aren't being shot, wait 10 seconds. Then regen our health
- if(health < 99) {
- if(isShot == false) {
- Wait();
- health += healthRegen * Time.deltaTime;
- }
- }
- }
- function Downed ()
- {
- Debug.Log("Downed");
- //Add downed animation here
- downed = true;
- }
- function Upped ()
- {
- Debug.Log("Revived!");
- //Add Revive animation here
- downed = false;
- }
- function Die ()
- {
- //Destroy(gameObject);
- Debug.Log("Dead");
- }
- function Wait ()
- {
- yield WaitForSeconds(regenTimer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement