How can I optimize this code with math?
I have 50 sprites that it needs to switch between and I don’t really want to use 50 if
statements
private void ManageBars()
{
if(playerController.Health <= 100 && playerController.Health > 98)
{
HealthBar.sprite = HealthBarSprites[0];
}
if(playerController.Health <= 98 && playerController.Health > 96)
{
HealthBar.sprite = HealthBarSprites[1];
}
if(playerController.Health <= 96 && playerController.Health > 94)
{
HealthBar.sprite = HealthBarSprites[2];
}
if(playerController.Health <= 94 && playerController.Health > 92)
{
HealthBar.sprite = HealthBarSprites[3];
}
}
Thank you!