using UnityEngine;
using UnityEngine.UI;
public class HealthBar : MonoBehaviour
{
public Image healthBarImage;
public Player player;
public void UpdateHealthBar() {
healthBarImage.fillAmount = Mathf.Clamp(player.health / player.maxHealth, 0, 1f);
}
}
using UnityEngine;
using UnityEngine.UI;
public class Player: MonoBehaviour
{
public float health, maxHealth;
public HealthBar healthBar;
public void TakeDamage(){
health -= 25;
healthBar.UpdateHealthBar();
}
void Update(){
if(Input.GetKeyDown(KeyCode.Space)){
TakeDamage();
}
}
}