Question by
GerPronouncedGrr · Jun 26, 2016 at 03:54 PM ·
proceduralui imagemodulus
Procedural updating of Zelda-like heart images
I'm attempting to use %
to check if the player's current health is even or odd, and update an n-dimensional array of UI images with sprites from another array. The sprite array has three indices, in which 0 = Empty Heart, 1 = Half Heart, and 2 = Full Heart. CurrentHealth
is set to 6 in Start()
.
public void UpdateHealthView()
{
int i;
for (i = 0; i < HeartImages.Length; i++)
{
if (CurrentHealth != 0)
{
HeartImages[i].sprite = i % CurrentHealth == 0 ? HeartSprites[2] : HeartSprites[1];
if (CurrentHealth < i)
{
HeartImages[i].sprite = HeartSprites[0];
}
}
else
{
HeartImages[i].sprite = HeartSprites[0];
}
}
}
I've run through the possible scenarios on paper and realised that my operation will not return what I want it to, but I can't figure out how to change the expression HeartImages[i].sprite = i % CurrentHealth == 0 ? HeartSprites[2] : HeartSprites[1];
to fix the issue.
Comment