set image fill amount

i have a healthbar using UI Image, then, how to make the healthbar amount decrease when the character get hit by enemy

healthbar script

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class hpBar : MonoBehaviour
{
	public Image healthBar; 
	public void UpdateHealth ()
	{   
		float HP = GetComponent<caroq> ().currentHp ();
		healthBar.fillAmount = HP/1;
	}
}

and i want to call that function in player script

thank you

I’m not sure what your set up is, but this is vaguely how you would do it:

hp -= damage;
UpdateHealth();

All you have to do is decrease the HP variable by the damage done and then update the healthBar.fillAmount. The healthBar updating is already done in your UpdateHealth() method, so you just have to call that after changing the HP variable.