using UnityEngine;
using System.Collections;

public class WeakSpot : MonoBehaviour {
    public GameObject objectToDestroy;

    public Animator animator;

    public float disappearTime = 1f;

    // Détruit l'ennemi si il rentre en collision avec le player
    /*private void OnTriggerEnter2D (Collider2D collision) {
        if (collision.CompareTag ("Player")) {
            Death ();
        }
    }*/

    public int maxHealth = 100;
    int currentHealth;
    void Start () {
        currentHealth = maxHealth;
    }

    public void TakeDamage (int damage) {
        currentHealth -= damage;

        // joue l'animation de mort
        if (currentHealth <= 0) {
            Death ();
        }
    }

    public void Death () {
        Debug.Log ("enemy is dead");
        this.animator.SetTrigger ("Death");
        this.GetComponent<BoxCollider2D> ().enabled = false;
        this.GetComponent<EnemyMovement>().speed = 0;
        //HandleDisappearTime();
        this.enabled = false;
    }

    /*public IEnumerator HandleDisappearTime()
    {
        yield return new WaitForSeconds(disappearTime);
   
    }*/
}