Health: Lose One Heart Per Hit (647998)

So, I have no idea what I’m doing. Long story short, this is the code I have:

switch (healthCount) {

case 6:
heart1.sprite = heartFull;
heart2.sprite = heartFull;
heart3.sprite = heartFull;
return;

case 5:
heart1.sprite = heartFull;
heart2.sprite = heartFull;
heart3.sprite = heartHalf;
return;

case 4:
heart1.sprite = heartFull;
heart2.sprite = heartFull;
heart3.sprite = heartEmpty;
return;

case 3:
heart1.sprite = heartFull;
heart2.sprite = heartFull;
heart3.sprite = heartFull;
return;

case 2:
heart1.sprite = heartFull;
heart2.sprite = heartFull;
heart3.sprite = heartEmpty;
return;

case 1:
heart1.sprite = heartFul;
heart2.sprite = heartEmpty;
heart3.sprite = heartEmpty;
return;

case 0:
heart1.sprite = heartEmpty;
heart2.sprite = heartEmpty;
heart3.sprite = heartEmpty;
return;
}

However, I do not want half-hearts. I just want the health system to be a simple trio, and each time the player is hit they lose one heart image. I honestly don’t even know how or where the current code is accessing the half-heart images. Otherwise, I would just replace those images.

  1. Delete the case 4, 5 and 6 code.
  2. Without seeing the rest of the code… There will be Sprite variables heartFull, heartHalf and heartEmpty. (Note your case 1: has misspelt heartFull, the compiler should pick this up so assuming it is a typo here)
    Delete the Sprite heartHalf; variable declaration

I will take a punt that this is a monobehaviour script and they are public variables so you should be able to see the names (heartFull etc) on the game object that the script is attached to; you can just drag a sprite there if you need to change the heart images.

I assume you have just used someone elses existing code for this?
Best bet is start with the basics; Unity Learn

First stop…

1 Like

Also… no need to duplicate the thread