using UnityEngine;
using System.Collections;

public class EnemyHealth : MonoBehaviour {

    public GameObject bloodParticles;
    public GameObject meat;

    public float health = 1.0f;


    private Animator anim;


    public float invul = 0.0f;

    public void damage(float amount) {

        if (invul > 0) {
            return;
        }

        invul = 0.8f;

        health -= amount;

        anim.SetTrigger("hurt");

        if (health <= 0) {
            Instantiate(bloodParticles, transform.position, Quaternion.identity);
            Instantiate(meat, transform.position, Quaternion.identity);
            Destroy(this.gameObject);
        }


    }

	// Use this for initialization
    void Start() {
        anim = GetComponent<Animator>();
	}
	
	// Update is called once per frame
	void Update () {
        if (invul > 0) {
            invul -= Time.deltaTime;
        }
	
	}
}
