summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Enemy/EnemyHealthScript.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Enemy/EnemyHealthScript.cs')
-rwxr-xr-xAssets/Scripts/Enemy/EnemyHealthScript.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/Assets/Scripts/Enemy/EnemyHealthScript.cs b/Assets/Scripts/Enemy/EnemyHealthScript.cs
new file mode 100755
index 0000000..c9d93be
--- /dev/null
+++ b/Assets/Scripts/Enemy/EnemyHealthScript.cs
@@ -0,0 +1,31 @@
+using UnityEngine;
+using System.Collections;
+
+public class EnemyHealthScript : MonoBehaviour {
+
+ public int Health = 100;
+
+ public GameObject DestroyAnimation;
+ GameObject DestroyAudio;
+
+ void Start () {
+ DestroyAudio = GameObject.FindGameObjectWithTag("EnemyDestroyAudio");
+ }
+
+ // Update is called once per frame
+ void Update () {
+
+ }
+
+ public void TakeDamage(int damage)
+ {
+ Health -= damage;
+ if (Health <= 0)
+ {
+ var animation = Instantiate(DestroyAnimation, transform.position, Quaternion.identity);
+ DestroyAudio.GetComponent<AudioSource>().Play();
+ Destroy(gameObject);
+ Destroy(animation, 1f);
+ }
+ }
+}