Created
October 15, 2015 19:48
-
-
Save Pritesh-Patel/17a5e94afa7b56536198 to your computer and use it in GitHub Desktop.
Simple unity health component.
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 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