using TMPro;
using UnityEngine;
using static UnityEngine.EventSystems.EventTrigger;

public class ChangeHealth : MonoBehaviour
{
    [Header("UI and HUD")]


    [SerializeField] public int deathCounter;
    [SerializeField] GameObject panel;
    [SerializeField] TMP_Text healthHUD;
    [SerializeField] public int standardHealth = 3;

    [Header("ScriptPile")]

    InventoryScript inventory;
    GameOver end;


    private void Awake()
    {
        inventory = panel.GetComponent<InventoryScript>();
        end = panel.GetComponent<GameOver>();
    }

    void Start()
    {
        deathCounter = 0;
        inventory.Health = standardHealth;
        Debug.Log(inventory.Health);
    }

    void Update()
    {
        healthHUD.text = inventory.Health.ToString();

        
    }

    public void GetHit()                //MUSS NOCH MIT ENEMIES VERKNÜPFT WERDEN
    {
        if (inventory.Health > 0)
        {
            inventory.Health -= 1;          //MAGIC NUMBER BITTE BEACHTEN
        }

        Debug.Log("Ouch, you bastard.");

        if (inventory.Health <= 0)
        {
            Die();
        }

    }


    public void Die()
    {
        deathCounter++;
        Debug.Log(deathCounter);
        end.CalculateCost();
        //Time.timeScale = 0;   //Wieder umlegen
        end.ShowDeathScreen();
        Debug.Log("rest in pizza");
        
    }


}
