Hey, sorry for the late reply. Anyway, maybe because your health is an integer and not float? Not really sure. Let me know if you have fixed it already :)
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?
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.
The player might have two colliders making it have a damage for each one. If not, try destroying the bullet when hitting the player before taking the damage. Let me know if it works :)
Hi great video, can you make tutorial with the health bar being attached to the player, and a 3D enemy attacks at close range and the health bar goes down? I am stuck right now looking for this tutorial online, can you help?
Lerp in our case is used to animate the health bar. Don’t decrease the health using lerp. Let me know if you are still struggling; I’ll be happy to help :)
What if I don't have a main camera? What if I have a follow camera? And what if I want to call the damage points slowly while holding down a key on the keyboard but from another script?
It doesn’t have to be on the main camera. You can put it on any object as long as it won’t be destroyed (removed/deleted from the scene). The main camera is just an example. You can call the Damage() method from another script by simply typing in an Update() method in the other script: if (Input.GetKey(KeyCode.*yourKey*) { HealthScript.Damage(5f); } There are many other ways to call the damage method from another script that you can find online :) Let me know if you need further help.
@@HypedCloud Wow! That was really fast! I'll try incorporating it. We got a little car game and I am trying to use this video to make a fuel meter. It might be that I am having troubles because I'm trying to call the functions through an acceleration method.
@@bunbunmikey7485 Hmmm.. Why don’t you drag the health script to the car, then in the script that has the acceleration method, you just create a new public Health script, then in the inspector, you just have to drag the car to it. public HealthScript health;
@@HypedCloud I created an empty game object to use as the bar. In the car prefab I add the meter and as I call the function from the carController I create a new bar and use that. Only problem I get now is that the bar turns red before it reaches halfway and as soon as it is below 0.5 the value starts to fluctuate. It goes up and down and get stuck around 0.47 to 0.49. It never hits zero.
Hi HGteam, You can use the Damage function in the onCollisionEnter(Collision other) { //check if it’s an enemy for example //then call the Damage function //like so: Damage(5); } NOTE: this will work if both Damage() and onCollisionEnter() are in the same script. However, if you have two different scripts and you want to call Damage(5) from another script you will have to define the Health script in it first: public Health health; then select it from the inspector just like how we did with the buttons. I prefer to use [SerializedField] instead of public (not so important). Anyway, if you are still struggling let me know :)
@@HypedCloud Erhmmm... Sadly that's not working... If you can help, here's my code: void OnCollisionEnter(Collision other) { GameObject.FindWithTag("enemy"); Damage(5); } (I'm really beginner :D)
health bar for Voxel is his skin, it becomes darker as health gets lower, debuffs also affects the color, poison is green, confusion is grey, scared is purple, and bleeding is Voxel leaking cytoplasm while red, Voxel has blue blood.
Right click on the hierarchy > Create > UI > Button. Then select the button and add a new “On Click” event and select the Health script from where you attached it to. Then choose which function / method you want to run from the dropdown menu. It is so easy to do. If you are still struggling, this might help you: www.tutorialspoint.com/unity/unity_the_button.htm
the worst thing you can do in a freaking guide is to time lapse, we want to see everything you kinda ruined it for me when you start to time lapse at the buttons , I can't even place my text in the slot of the main camera from within the script, as a new beginner to coding this video is a 4/10 for me.
This video will be my litmus test, I've grown exhausted of the click bait thumb nails, if this is actually click bait and kiers starmer wasn't humiliated by king charles and if the headline "he refuses to listen" wasn't quoted from the king then, I will forever henceforth block all channels that use this specific tactic... lets begin.
The audio volume is a little bit low. Sorry about that.
Check out the description for links and timeline. 🔗⏰
create sprite is missing and i download ur ring png but i cant put it image source section
okey i solve it just changn texture type to 2d uı
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
I thought i was the only one who wanted smooth bars! Thx so much for this!
When I started watching the video, my question was answered instantly. After watching more, I realized my question wasn't big enough
Thanks for this nice tutorial buddy. 2024 and still relevant!
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;
}
Just what I needed.
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?
Hey, sorry for the late reply. Anyway, maybe because your health is an integer and not float? Not really sure. Let me know if you have fixed it already :)
very solid video man, thanks a bunch
Thanks this was very helpful!
You helped me with this video of yours
Thanks a lot...
U just earned my sub
Awesome! :D
Thank you for sharing a very great idea of very cool Health Bars :)
Thank you. You helped me how smoothly change image
This was amazing, thank you.
Excellent Job on your video👏👏👏👏
Grate tutorial bro! you should keep making tutorial videos. Liked!
Thank You!
Thank you so much!
Very useful & clear explanation,
Thanks !
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.
Amazing!
Excellent, love it
Life saver!
Thanks for this tutorial, it is so good content!
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?
I can't apply the text layer to the text frame on the camera :(
These were pretty good. A little worried about that for loop in the update method tho...
THANKS YOU VERY MUCH
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.
The player might have two colliders making it have a damage for each one. If not, try destroying the bullet when hitting the player before taking the damage. Let me know if it works :)
@@HypedCloud yeah thanks bro
Thank you for this, you’ve gained a sub from me
Você é monstro!
Hi great video, can you make tutorial with the health bar being attached to the player, and a 3D enemy attacks at close range and the health bar goes down? I am stuck right now looking for this tutorial online, can you help?
i m at the same point right now
Hi, Great tutorial! How can make a health pickup for healing this specific health script?
Hmm but I can't put my Health Text into the Main Camera Text slot :(.
Also, you can't create a sprite anymore. It's an image now
Wow very helpful
Glad I could help :D
Thanks :)
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.
Lerp in our case is used to animate the health bar. Don’t decrease the health using lerp.
Let me know if you are still struggling; I’ll be happy to help :)
Awesome tutorial but i have a problem when i click on the button the health bar doesn't reduce if someone can help me
Need help, it says “The script don’t inherit a native class that can manage a script “
Anyone knows a fix?
What if I don't have a main camera? What if I have a follow camera? And what if I want to call the damage points slowly while holding down a key on the keyboard but from another script?
It doesn’t have to be on the main camera. You can put it on any object as long as it won’t be destroyed (removed/deleted from the scene). The main camera is just an example.
You can call the Damage() method from another script by simply typing in an Update() method in the other script:
if (Input.GetKey(KeyCode.*yourKey*)
{
HealthScript.Damage(5f);
}
There are many other ways to call the damage method from another script that you can find online :)
Let me know if you need further help.
@@HypedCloud Wow! That was really fast! I'll try incorporating it. We got a little car game and I am trying to use this video to make a fuel meter. It might be that I am having troubles because I'm trying to call the functions through an acceleration method.
@@bunbunmikey7485 Hmmm.. Why don’t you drag the health script to the car, then in the script that has the acceleration method, you just create a new public Health script, then in the inspector, you just have to drag the car to it.
public HealthScript health;
@@HypedCloud I created an empty game object to use as the bar. In the car prefab I add the meter and as I call the function from the carController I create a new bar and use that. Only problem I get now is that the bar turns red before it reaches halfway and as soon as it is below 0.5 the value starts to fluctuate. It goes up and down and get stuck around 0.47 to 0.49. It never hits zero.
thx
Hi! How can I make on collision the HP is lowered by 5? (Sry for the bad eng)
Hi HGteam,
You can use the Damage function in the onCollisionEnter(Collision other)
{
//check if it’s an enemy for example
//then call the Damage function
//like so:
Damage(5);
}
NOTE:
this will work if both Damage() and onCollisionEnter() are in the same script. However, if you have two different scripts and you want to call Damage(5) from another script you will have to define the Health script in it first:
public Health health;
then select it from the inspector just like how we did with the buttons. I prefer to use [SerializedField] instead of public (not so important).
Anyway, if you are still struggling let me know :)
@@HypedCloud Thanks ^^
@@HypedCloud Erhmmm... Sadly that's not working... If you can help, here's my code:
void OnCollisionEnter(Collision other)
{
GameObject.FindWithTag("enemy");
Damage(5);
}
(I'm really beginner :D)
@@Hurkaaa try:
if (other.tag == “enemy”)
Damage(5);
@@HypedCloud Nope. Not working
health bar for Voxel is his skin, it becomes darker as health gets lower, debuffs also affects the color, poison is green, confusion is grey, scared is purple, and bleeding is Voxel leaking cytoplasm while red, Voxel has blue blood.
it says can't add component health cause script class cannot be found
name your script Health with a capital or health
how do you create the buttons
Right click on the hierarchy > Create > UI > Button. Then select the button and add a new “On Click” event and select the Health script from where you attached it to. Then choose which function / method you want to run from the dropdown menu. It is so easy to do. If you are still struggling, this might help you: www.tutorialspoint.com/unity/unity_the_button.htm
the audio is holy shit....
the worst thing you can do in a freaking guide is to time lapse, we want to see everything you kinda ruined it for me when you start to time lapse at the buttons , I can't even place my text in the slot of the main camera from within the script, as a new beginner to coding this video is a 4/10 for me.
This video will be my litmus test, I've grown exhausted of the click bait thumb nails, if this is actually click bait and kiers starmer wasn't humiliated by king charles and if the headline "he refuses to listen" wasn't quoted from the king then, I will forever henceforth block all channels that use this specific tactic... lets begin.
A 2x speed and 4 minutes late... welcome to the forgotten pile.
This post was on a different video... odd, I never posted on this video =/.
This is so great !! Thank you so much brother !!