title: Unity C# loops: Health Bar with Hearts
body: <p>I have problem, I would like to add a halfHeart image to empty bar if the currentHealth is 25 or its multiple except of multiples of 50, because if currentHealth is for example 50 I want to show my fullHeart image in the bar where the halfHeart image used to be. I used the if I &lt; currentHealt / 50 which shows fullHeart image inside of the empty bar if the players hp is 50, 100, 150, 200 etc. Now I just want to use the halfHearts if there are 2 fullHeart so the current hp is for example 100 and we drink potion which adds 25, so the currentHealt will be 125 which means we want a halfHeart to take place.</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  
  public class PlayerCombat : MonoBehaviour
  {
      public int maxHealth = 600;
      public int currentHealth;
      public int numOfHearts;
      public Transform attackPoint;
      public LayerMask enemyLayers;
  
      public float attackRange = 0.5f;
      public int attackDamage = 50;
  
      public float attackRate = 2f;
      float nextAttackTime = 0f;
  
      public Image[] hearts;
      public Sprite fullHeart;
      public Sprite halfHeart;
      public Sprite emptyHeart;
  
  
  
      void Start()
      {
          currentHealth = maxHealth;
      }
  
      void Update()
      {
  
          if (Time.time &gt;= nextAttackTime)
          {
  
              if (Input.GetKeyDown(KeyCode.Mouse0))
              {
                  Attack();
                  nextAttackTime = Time.time + 1f / attackRate;
              }
          }
  
          for (int i = 0; i &lt; hearts.Length; i++)
          {
  
              if (i &lt; currentHealth / 50)
              {
  
                  hearts[i].sprite = fullHeart;
  
                  if (currentHealth % 50 == 0 - 25)
                  {
  
                  }
  
  
              }
              else
              {
  
                  hearts[i].sprite = emptyHeart;
  
              }
  
              if (i &lt; numOfHearts)
              {
                  hearts[i].enabled = true;
              }
              else
              {
                  hearts[i].enabled = false;
              }
  
          }
  
      }
  
      void Attack()
      {
          Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
  
          foreach (Collider2D enemy in hitEnemies)
          {
              enemy.GetComponent&lt;Enemy&gt;().TakeDamage(attackDamage);
          }
  
      }
  
      void OnDrawGizmosSelected()
      {
          if (attackPoint == null)
              return;
  
          Gizmos.DrawWireSphere(attackPoint.position, attackRange);
      }
  }
  </code></pre>