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

public class Stats : MonoBehaviour {

    public int maxHP = 5, currentHP;
    public GameObject UIManager;
    public GameObject gmover;
	// Use this for initialization
	void Start () {
        currentHP = maxHP;
	}

    void TakeDamage()
    {
        currentHP--;
        if (gameObject.CompareTag("Player"))
        {
            UIManager.SendMessage("DeductLife", currentHP);
        }
    }

    void CheckIfDead()
    {
        if (currentHP <= 0)
        {
            Destroy(gameObject);
            gmover.gameObject.SetActive(true);
        }
    }
    
	
	// Update is called once per frame
	void Update () {       
        CheckIfDead();
        if (Input.GetKeyDown(KeyCode.Space))
        {
            TakeDamage();
        }
	}
}
