Project Tellus heart health system

Here’s my health system. I’m going to try to get it to work with half-hearts as well, but at the moment it’s just full or empty hearts.

1 Like

Made it so the hearts could be divided however you want. I chose 4ths, but just change the HealthPerHeart variable and it can be whatever. I’d like Health to be an Integer but ran into the issue of not being able to get a float value (for the Fill) from dividing two integers… Not sure if there’s a way around that.

Here’s my code. Instead of doing it in Update it’s a public function that can be called only when the health changes and needs to be updated:

   public float health;
    public int numOfHearts; // the amount of heart containers visible
    [SerializeField] int healthPerHeart = 4;

    public Image[] fullHearts;
    public Image[] emptyHearts;

    private float heartHealthRatio;

    private void Awake()
    {
        UpdateHealthUI(0);
    }

    public void UpdateHealthUI(int healthUpdateAmount)
    {
        health = health + healthUpdateAmount;

        heartHealthRatio = health / healthPerHeart;

        if (health > numOfHearts * healthPerHeart) // don't allow there to be more health than heart containers can contain
        {
            health = numOfHearts * healthPerHeart;
        }

        for (int i = 0; i < fullHearts.Length; i++)
        {
            if (i + 1 < heartHealthRatio)
            {
                fullHearts[i].fillAmount = 1;
            }
            else
            {
                fullHearts[i].fillAmount = heartHealthRatio - i;
            }

            if (i < numOfHearts)
            {
                fullHearts[i].enabled = true;
            }
            else
            {
                fullHearts[i].enabled = false;
            }
        }

        for (int i = 0; i < emptyHearts.Length; i++)
        {
            if (i < numOfHearts)
            {
                emptyHearts[i].enabled = true;
            }
            else
            {
                emptyHearts[i].enabled = false;
            }
        }
    }

Hey Jason_Martin,

Just wanted to say that I loved this little clip! Huge fan of Legend of Zelda so the hearts really are awesome! And your gameplay in general looks pretty neat :slight_smile: Overall, great job!

1 Like

Hey Jason, this looks killer!

Two questions…

  1. How did you achieve that sort of “cave” effect? As far as I can tell, I’ve read a lot that this wasn’t possible in unity, digging out of the terrain. I want this SO bad!

  2. Where’d you get the character model? Reminds me of Gravity Rush for the PS4/Vita.

Thanks! The terrain here is actually just using cubes. Later on in the project I make a terrain in Unity, then export it into Blender to tweak it more.

The character is UnityChan (Free on the Asset Store). I did a few tweaks to her textures, and got her animations to work with the Standard character controller.

Privacy & Terms