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


public class Tank2Health : MonoBehaviour {

    public static Tank2Health instance;

    public int startHealth = 100;
    public int currentHealthT2;

    public Slider tank2Slider;

 //   bool isDamaged;
    bool isDead;

    public GameObject explosion;


    void Start () {
        currentHealthT2 = startHealth;
	}

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

    void Update () {
		
	}

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

        currentHealthT2 -= damage;

        tank2Slider.value = currentHealthT2;

        if (currentHealthT2 <= 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);
    }
}
