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
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