using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EnemyHealth : MonoBehaviour {

    public static EnemyHealth instance;

    public int startHealth = 100;
    public int currentHealth;

    public Slider enemyHealthSlider;

//    bool isDamaged;
    bool isDead;

    public GameObject explosion;

    void Start () {
        currentHealth = startHealth;
	}

    void MakeInstance() {
        if (instance == null) {
            instance = this;
        }
    }

	void Update () {
		
	}

    public void EnemyDamage(int damage) {
   //     isDamaged = true;

        currentHealth -= damage;

        enemyHealthSlider.value = currentHealth;

        if (currentHealth <= 0 && !isDead) {
            Dead();
        }
    }

    void Dead() {
        isDead = true;
        Debug.Log("Enemy Dead!!");
        gameObject.SetActive(false);
        GameObject exploded = (GameObject)Instantiate(explosion, transform.position, transform.rotation);
        Destroy(exploded, 1.2f);
    }
}
