Resim
using UnityEngine.UI;
public class healty : MonoBehaviour
{
    public Image[] heartPics;
    public int maxValue=7, currentValue=7;

    void damage(int amount) 
    {
        heartPics[currentValue - 1].enabled = false;
        currentValue -= amount;
    }
    void healAdd(int amount)
    {
        currentValue += amount;
        heartPics[currentValue - 1].enabled = true;
    }

    private void Update()
    {
        if (currentValue >= maxValue)
        {
            currentValue = maxValue;
        }
        if (Input.GetKeyDown(KeyCode.J))
        {
            if (currentValue < maxValue)
            {
                healAdd(1);
                Debug.Log("Eklendi");
            }
        }
        if (Input.GetKeyDown(KeyCode.G))
        {
            if (currentValue > 0)
            {
                damage(1);
            }
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "HPPotion")
        {
            if (currentValue < maxValue)
            {
                healAdd(1);
                Destroy(collision.gameObject);
            }
            
        }
    }
}