diff options
| author | Tom Harley | 2018-09-03 23:34:21 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-09-03 23:36:01 +0100 |
| commit | 5440734d820606b29a795c46172ade5d7eba8efb (patch) | |
| tree | 85867f40afb02cfa2a5028b515ed0a195866b7e9 /Assets/Scripts/ICanDie.cs | |
| download | powerless-5440734d820606b29a795c46172ade5d7eba8efb.tar.gz powerless-5440734d820606b29a795c46172ade5d7eba8efb.zip | |
Initial commit
Diffstat (limited to 'Assets/Scripts/ICanDie.cs')
| -rw-r--r-- | Assets/Scripts/ICanDie.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Assets/Scripts/ICanDie.cs b/Assets/Scripts/ICanDie.cs new file mode 100644 index 0000000..d6ff6d1 --- /dev/null +++ b/Assets/Scripts/ICanDie.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ICanDie : MonoBehaviour { + public float health = 3; + + public AudioClip deathNoise; + public float deathNoiseVolume = 1f; + + private AudioSource audio; + + void Start() { + audio = GetComponent<AudioSource>(); + } + + public void Hit(float damage) { + health -= damage; + + if (health <= 0) { + Die(); + } + } + + public void Die() { + if (deathNoise) audio.PlayOneShot(deathNoise, deathNoiseVolume); + + GetComponent<SpriteRenderer>().enabled = false; + GetComponent<BoxCollider2D>().enabled = false; + } +} |
