can GetComponent().fillAmount -= 0.1f; work with on collision enter?, GetComponent().fillAmount -= 0.1f; works fine if attached to getkeydown but not for oncollisionenter

can GetComponent().fillAmount -= 0.1f; work with on collision enter?,{
public Rigidbody Enemy;
public Image healthBar;
public void OnCollisionEnter(Collision collision)
{
GetComponent().fillAmount -= 0.1f;

}

}

You have to use :

OnCollisionEnter(Collision collision) 
{ 
     collison.gameObject.transform.GetComponent(scriptName).fillAmount -= 0.1f; //'scriptName' should be replaced with the name of the desired script
}