From 115f77bda0246a00f6e17469685c67746bdbd29d Mon Sep 17 00:00:00 2001 From: nirav Date: Sat, 12 Dec 2020 07:18:36 +0000 Subject: Initial commit --- Assets/Scripts/Enemy/EnemyHealthScript.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 Assets/Scripts/Enemy/EnemyHealthScript.cs (limited to 'Assets/Scripts/Enemy/EnemyHealthScript.cs') 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().Play(); + Destroy(gameObject); + Destroy(animation, 1f); + } + } +} -- cgit v1.2.3