Using debug.log to show health bar is working

I am brand new to unity and C#. I am working with a team to create a video game. I am making the health bar. To show it is working, I am using debug.log to display the message “the health bar is displaying:” and then the number of HP, which I got from getHP that keeps track of the current HP. I have it in fixed update, so it is displaying the message thousands of times. Is there a way I can change it so it will only display once every time there is a change? or what can I add to do this? Here is the part I’m struggling on:

void FixedUpdate()
{
playerhealth.getHP();
Debug.Log(“health bar is displaying” + playerhealth.getHP());
}
,I am brand new to unity and c#. I am working on a team to create a rougelike game. I am working on the health bar for the player. To show that it is working, I am using debug.log to display a message health bar is displaying and then the number of HP. I have the debug.log in the fixed update. So it shows this message thousands of times. Is there a way I can change this? How can I get it so it only displays once each time there is a change in HP.
Here’s my code for the message, getHp is what is used to fetch the current HP :

void FixedUpdate()
{
playerhealth.getHP();
Debug.Log(“health bar is displaying” + playerhealth.getHP());
}

@jesusfreakmir123
You can use a nice function like this:

public void TakeDamage(int amount)
{
    currentHealth -= amount;
    if (currentHealth <= 0)
    {
        currentHealth = 0;
        Debug.Log("Dead!");
    }
    else {
        Debug.Log("Health: " + currentHealth);
    }
}

If you have access to the PlayerHealth source code you can use a property to register any changes. If you don’t have access you can keep track of the value yourself and check for changes:

using UnityEngine;

public class PlayerHealth : MonoBehaviour 
{
	private int hp;

	public int HP
	{
		get { return hp; }
		set
		{
			if(value != hp)
			{
				hp = value;
				Debug.Log("Player health set to: " + hp);
			}
		}
	}
}

public class SomeClass : MonoBehaviour
{
	public PlayerHealth playerHealth;

	private int lastHP;

	private void Update()
	{
		if(playerHealth.HP != lastHP)
			Debug.Log("Player health has changed to: " + playerHealth.HP);
		
		lastHP = playerHealth.HP;
	}
}