Skip to content

Instantly share code, notes, and snippets.

@CSaratakij
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CSaratakij/159b783376eadfcaad55 to your computer and use it in GitHub Desktop.
Save CSaratakij/159b783376eadfcaad55 to your computer and use it in GitHub Desktop.
HealthController(Author: Chatchai Saratakij)
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