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

public static class GlobalEvents
{
    public delegate void OnHPLoss();

    public static OnHPLoss OnHPLossEvent;
    public static void SendHPLossEvent()
    {
        if(OnHPLossEvent != null)
        {
            OnHPLossEvent();
        }
    }
}
public class CatBossScript : MonoBehaviour
{
    int hp = 8;
	// Use this for initialization
	void Start ()
    {
        hp = 8;
        GlobalEvents.OnHPLossEvent += HandleHPLoss;
    }

    void OnDestroy()
    {
        GlobalEvents.OnHPLossEvent -= HandleHPLoss;
    }
	
	// Update is called once per frame
	void HandleHPLoss()
    {
        hp--;
        if (hp == 0) {
            Debug.Log("rundeath");
            var level = FindObjectOfType(typeof(CatHitScript));
            var lev = level as CatHitScript;
            lev.Death();
        }
        GetComponent<Animator>().SetInteger("HP", hp);
    }
}
