Created
June 19, 2021 11:48
-
-
Save yanniboi/a8669069456425383c62bfc826271e4b to your computer and use it in GitHub Desktop.
Devlog - Tower Offender - Radial heart fill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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