Skip to content

Instantly share code, notes, and snippets.

@Pritesh-Patel
Created October 15, 2015 19:48
Show Gist options
  • Save Pritesh-Patel/17a5e94afa7b56536198 to your computer and use it in GitHub Desktop.
Save Pritesh-Patel/17a5e94afa7b56536198 to your computer and use it in GitHub Desktop.
Simple unity health component.
using UnityEngine;
using System.Collections;
public class Health : MonoBehaviour {
public int maxHealth;
public int currentHealth;
// Use this for initialization
void Start () {
currentHealth = maxHealth;
}
public void TakeDamage(int dmg)
{
if(currentHealth - dmg < 0) currentHealth = 0;
else currentHealth -= dmg;
}
public void AddHealth(int health)
{
if (currentHealth > maxHealth) currentHealth = maxHealth;
else currentHealth += health;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment