I want to increase the health bar when I press a button.

Hi,
I am a beginner in unity and I have this code that makes the health bar goes down with time and I don’t know how to make it refill when i press a button (UI Image ) without changing the code.
thanks for answering

all help is appreciated.

In Update() add this:

if(Input.GetKeyDown(KeyCode.R)){ playerHealth = 1; bar.fillAmount = playerHealth; }

if(Input.GetKeyDown(KeyCode.Space)){
//Your Code
//Unity - Scripting API: KeyCode
}
OR

if(Input.GetKeyDown("space")){
    //Your Code
   https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html
}

Or with buttons:

public class TaskIcon : MonoBehaviour,IPointerClickHandler{
	public float Health;
	public void OnPointerClick(PointerEventData eventData){
		//code
	}
}

Or with the UI Component Button https://docs.unity3d.com/ScriptReference/UI.Button.html