Last active
August 29, 2015 14:12
-
-
Save CSaratakij/159b783376eadfcaad55 to your computer and use it in GitHub Desktop.
HealthController(Author: Chatchai Saratakij)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public sealed class Health : MonoBehaviour { | |
[SerializeField] | |
int health; | |
[SerializeField] | |
int maxHealth; | |
bool isAlive; | |
public int CurrentHealth { get { return health; } } | |
public int CurrentMaxHealth { get { return maxHealth; } } | |
public bool IsAlive { get { return isAlive; } } | |
public Health() { | |
health = 100; | |
maxHealth = 100; | |
isAlive = true; | |
} | |
void Update() { | |
if (health > maxHealth) { | |
FullRegen(); | |
} | |
else { | |
if (health < 0) | |
Clear(); | |
isAlive = (health > 0) ? true : false; | |
} | |
} | |
public void FullRegen() { | |
health = maxHealth; | |
} | |
public void Clear() { | |
health = 0; | |
} | |
public void Regen(int health) { | |
this.health += health; | |
} | |
public void Remove(int health) { | |
this.health -= health; | |
} | |
public void AddCurrentMaxHealth(int maxHealth) { | |
this.maxHealth += maxHealth; | |
} | |
public void RemoveCurrentMaxHealth(int maxHealth) { | |
this.maxHealth -= maxHealth; | |
} | |
public void SetCurrentHealth(int health) { | |
this.health = health; | |
} | |
public void SetCurrentMaxHealth(int maxHealth) { | |
this.maxHealth = maxHealth; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment