Skip to content

Instantly share code, notes, and snippets.

@yanniboi
Created June 19, 2021 11:48
Show Gist options
  • Save yanniboi/a8669069456425383c62bfc826271e4b to your computer and use it in GitHub Desktop.
Save yanniboi/a8669069456425383c62bfc826271e4b to your computer and use it in GitHub Desktop.
Devlog - Tower Offender - Radial heart fill
public class HealthController : MonoBehaviour
{
[SerializeField]
private Image[] _hearts;
private float _currentHealth;
public void UpdateDisplay()
{
int remainingHealth = _currentHealth;
foreach (var heart in _hearts)
{
float fill;
if (remainingHealth > 4)
{
fill = 4;
}
else
{
fill = remainingHealth;
}
heart.fillAmount = fill / 4;
remainingHealth = remainingHealth - 4;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment