From 5440734d820606b29a795c46172ade5d7eba8efb Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 3 Sep 2018 23:34:21 +0100 Subject: Initial commit --- Assets/Scripts/ICanDie.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Assets/Scripts/ICanDie.cs (limited to 'Assets/Scripts/ICanDie.cs') 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(); + } + + public void Hit(float damage) { + health -= damage; + + if (health <= 0) { + Die(); + } + } + + public void Die() { + if (deathNoise) audio.PlayOneShot(deathNoise, deathNoiseVolume); + + GetComponent().enabled = false; + GetComponent().enabled = false; + } +} -- cgit v1.2.1