Hi all,
I have been trying without luck to implement other people’s code from similar questions to my own script. Basically I have a health bar that I would like to be constantly ticking down e.g. losing 1 health point/second. Here is the code, any help would be greatly appreciated. Thanks in advance.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthController : MonoBehaviour
{
public UnityEngine.Events.UnityEvent OnDeath;
[SerializeField] public float playerHealth;
[SerializeField] public float maxHealth;
[SerializeField] public Image healthImage;
[SerializeField] public int damage;
void Start()
{
}
public void ButtonClick()
{
playerHealth -= damage;
UpdateHealth();
if(playerHealth < 0)
OnDeath.Invoke();
}
private void UpdateHealth()
{
healthImage.fillAmount = playerHealth / maxHealth;
}
}