C# Script on Health bar and armor

I need help guys. I have 2 scripts which work like Health and armor system and i have trouble. I need player die when currentHealth = 0, but he die when currentHealth = 10. Help me

public class HealthSystem : MonoBehaviour
{
    [SerializeField] private int maxHealth = 100;
    [SerializeField] private int maxArmor = 50;

    private int currentHealth;
    private int currentArmor;

    // Public properties for accessing the current state
    public int CurrentHealth => currentHealth;
    public int CurrentArmor => currentArmor;

    // Initialization method
    private void Start()
    {
        currentHealth = maxHealth;
        currentArmor = maxArmor;
    }

    // Method for taking damage
    public void TakeDamage(int damage)
    {
        Debug.Log($"Initial Health: {currentHealth}");
        Debug.Log($"Initial Armor: {currentArmor}");
        Debug.Log($"Damage Received: {damage}");

        int remainingDamage = damage;

        if (currentArmor > 0)
        {
            Debug.Log($"Armor before damage: {currentArmor}");

            if (currentArmor >= remainingDamage)
            {
                currentArmor -= remainingDamage;
                remainingDamage = 0;
            }
            else
            {
                remainingDamage -= currentArmor;
                currentArmor = 0;
            }

            Debug.Log($"Armor after damage: {currentArmor}");
            Debug.Log($"Remaining Damage after Armor: {remainingDamage}");
        }

        if (remainingDamage > 0)
        {
            Debug.Log($"Health before damage: {currentHealth}");
            currentHealth -= remainingDamage;
            Debug.Log($"Health after damage: {currentHealth}");
        }

        if (currentHealth <= 0)
        {
            currentHealth = 0;
            Die();
        }
        else
        {
            Debug.Log($"Current Health After Damage: {currentHealth}");
        }
    }

    // Method called when the character dies
    private void Die()
    {
        Debug.Log($"{gameObject.name} died.");
        gameObject.SetActive(false);

        CharactersBehavior behavior = GetComponent<CharactersBehavior>();
        if (behavior != null)
        {
            behavior.OnDeath();
        }
    }
}
public class CharactersBehavior : MonoBehaviour
{
    [SerializeField] private CharacterType characterType;
    private HealthSystem healthAndArmor;

    public enum CharacterType
    {
        Player,
        Enemy,
        Ally
    }

    private void Start()
    {
        healthAndArmor = GetComponent<HealthSystem>();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            healthAndArmor.TakeDamage(10);
        }
    }

    public void OnDeath()
    {
        switch (characterType)
        {
            case CharacterType.Player:
                Debug.Log("Player died. End of the game.");
                break;
            case CharacterType.Enemy:
                Debug.Log("enemy died.");
                break;
            case CharacterType.Ally:
                Debug.Log("Ally died.");
                break;
        }
    }
}

Sounds like a bug… time to start debugging!

Select some of the messages in your console, see what function called them. That way at least you can see the callstack below the log and see who called it.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

I press SPACE 10 times, when health and armor in Inspector are 50 and 50
Initial Health: 10; Initial Armor: 0; Damage Received: 10; Health before damage: 10; Health after damage: 0;
Player died.;
Player died. End of the game;

I tested your code and didn’t see the bug you’re talking about. Everything was logical: after the ninth press of the spacebar, there were 10 health points and zero armor left, and after the tenth press of the spacebar, the player died.