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); } } }