Three Cool Health Bars in Unity (2022/2020)

preview_player
Показать описание
This is a Unity tutorial that will show you how to make three different health/mana bar styles. The bars will gradually increase and decrease with color changing.

----------| Related Links 🔗 |----------

----------| Timeline ⏰ |----------
-(🚩) are the main keys.
00:00 - Introduction.
00:10 - Starting Tutorial (First Health Bar). 🚩
03:03 - Making the health bar smoother with colors.
04:09 - Second Health Bar (Ring Health Bar). 🚩
04:40 - Last Health Bar (Health Points Bar). 🚩
06:09 - Ending (Final Result). 🏁

🙋‍♂️ Follow Me:
Рекомендации по теме
Комментарии
Автор

The audio volume is a little bit low. Sorry about that.
Check out the description for links and timeline. 🔗⏰

HypedCloud
Автор

This is the best health bar tutorial i’ve seen. I’ve worked with sliders previously, but i wasn’t satisfied with that, this is better

laczikmarton
Автор

I thought i was the only one who wanted smooth bars! Thx so much for this!

toxicrez
Автор

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Health : MonoBehaviour
{
public Text healthText;
public Image healthBar;

float health, maxHealth = 100;
float lerpSpeed;

private void Start()
{
health = maxHealth;
}

private void Update()
{
healthText.text = "Health: " + health + "%";
if (health > maxHealth) health = maxHealth;

lerpSpeed = 3f * Time.deltaTime;

HealthBarFiller();
ColorChanger();
}

void HealthBarFiller()
{
healthBar.fillAmount = Mathf.Lerp(healthBar.fillAmount, health / maxHealth, lerpSpeed);
}

void ColorChanger()
{
Color healthColor = Color.Lerp(Color.red, Color.green, (health / maxHealth));

healthBar.color = healthColor;

}

public void Damage(float damagePoints)
{
if (health > 0)
health -= damagePoints;
}
public void Heal(float healingPoints)
{
if (health < maxHealth)
health += healingPoints;

}

vicentegirardin
Автор

When I started watching the video, my question was answered instantly. After watching more, I realized my question wasn't big enough

thomasthetankcat
Автор

Thanks for this nice tutorial buddy. 2024 and still relevant!

fulgencejuniorlohore
Автор

Thank you for sharing a very great idea of very cool Health Bars :)

rachapongwatana
Автор

Thank you. You helped me how smoothly change image

narsower
Автор

Grate tutorial bro! you should keep making tutorial videos. Liked!

SurpriseMotherFaker
Автор

You helped me with this video of yours
Thanks a lot...

Massive_M
Автор

Very useful & clear explanation,
Thanks !

aureliencord
Автор

This is so great !! Thank you so much brother !!

GameDesignverse
Автор

Thanks for this tutorial, it is so good content!

misal-isahabe
Автор

Note: You can't use TMP(Text Mesh Pro) for the text field you should use the old one if you would like for newer version of unity it Legacy.

pytz
Автор

Thank you for this, you’ve gained a sub from me

tegomlee
Автор

These were pretty good. A little worried about that for loop in the update method tho...

RicardoADev
Автор

I know I'm late... but for some reason my color changing doesn't transition between colors, and instead changes to the red color as soon as damage is taken. Can anyone help or know why this could be?

wratio
Автор

Nice and Concise!I was having issues applying health/maxhealth with my list.count/maximum. It works when I *0.1 but not /10. Do you know why?

ZacharyAghaizu
Автор

Dude I have a problem in my game. That is, the player has a script which has a take hit value, that is if the player get hit by enemy bullet it will decrease the value because it is a health bar slider. In that, I've set the value as 1, so that if enemy shoots a bullet it takes 1 damage. But the player gets 2 damage hit. What to do bro. Any suggestions.

dragonballz
Автор

When I add damage of 25, instead of it going to .25 it goes to "0.0388175." Something in the Mathf lerp is messing it up.

Mrazgoodaz