I need help with a health script

i want to have my health script call a void function if the “health” integer value is 0. here is my script.

`
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class MoneyManager : MonoBehaviour
{
    public int health;
    public TextMeshPro healthText;
    public DeathScript deathScirpt;

    void Update()
    {
        healthText.text = health.ToString();

    }

    public void Removerealhealth(int removehealth)
    {
        health -= removehealth;
    }

    void SetRealHealth(int newValue)
    {
        health = newValue;
    }

}
`

You could add a getter/setter to your public health integer like this :

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

public class MoneyManager : MonoBehaviour
{
    private int health;
    public TextMeshPro healthText;
    public DeathScript deathScript;

    public int Health
    {
        get { return health; }
        set
        {
            health = value;
            healthText.text = health.ToString();
            if (health <= 0)
            {
                HandleDeath();
            }
        }
    }

    public void RemoveRealHealth(int removeHealth)
    {
        Health -= removeHealth;
    }

    public void SetRealHealth(int newValue)
    {
        Health = newValue;
    }

    private void HandleDeath()
    {
        // Empty implementation
    }
}

Seems you need to work a bit more on the core c# concepts. Good luck

i am just learning c#, i looked trough other scripts and kinda taught myself.

i have also figured it out by myself, but thanks for trying! i appreciate it.