how to make a healthbar increase

I’m trying to add to an existing script a way to increase health by 10 points, the health pickup is destroyed so thats no problem. Im getting a CS0019 error can anyone help?

public PlayerHealth playerHealth;
public Slider healthSlider; 
public float HealthUp = 10;
//PlayerHealth.currenntHealth playerHealth.currentHealth;
	
void OnTriggerEnter (Collider col) 
{
	if (col.gameObject.tag == "Player")

	{
		Destroy(gameObject);
		Debug.Log ("pickup working");
	}
}

private void Update ()
{
	if (playerHealth < 100)

		playerHealth = playerHealth + HealthUp;
}

The issue is that you are trying to compare to different types int vs playerHealth.

 if (playerHealth < 100) // <---- PlayerHealth vs Integer
         playerHealth = playerHealth + HealthUp; // <---- PlayerHealth vs float

You either need to change player health to a float or add a health component to the PlayerHealth class that is a float

Example 1:

Public float playerHealth = 100;
...
if (playerHealth < 100)
    playerHealth += HealthUp;

Example 2:

if (playerHealth.health < 100)
   playerHealth.health += HealthUp;

If I understand your question correctly, you may wish to use “Invoke Repeat”

Thus, as you suggest in your question, you would have some sort of test to see if your health is below a certain amount (playerHealth < maxHealth) etc. If so, you would do something like this:

void Start()
    {
        InvokeRepeating("HealthIncrease", 5.0f, 1.5f);
    }

    void HealthIncrease()
    {
        Health = Health + addSomeNewHealth;
    }

So, the function “HealthIncrease” would be called. After 5.0 seconds it would begin. Then every 1.5 seconds it would increase your health by the “addSomeNewHealth” amount. Of course, you would use whatever time and increase amounts were appropriate.

Good luck and I’m sorry if this isn’t what you were asking.