summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Enemy2/NewEnemyHealth.cs
blob: 44202523da6707d219b5f533018826f03167278b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using UnityEngine;
using System.Collections;

public class NewEnemyHealth : 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(animation, 1f);
            Destroy(transform.parent.gameObject);            
        }

    }
}