Three Cool Health Bars in Unity (2024/2020)

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ธ.ค. 2024

ความคิดเห็น • 76

  • @HypedCloud
    @HypedCloud  4 ปีที่แล้ว +13

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

    • @Maskeowl
      @Maskeowl 2 ปีที่แล้ว

      create sprite is missing and i download ur ring png but i cant put it image source section

    • @Maskeowl
      @Maskeowl 2 ปีที่แล้ว

      okey i solve it just changn texture type to 2d uı

  • @laczikmarton2745
    @laczikmarton2745 3 ปีที่แล้ว +14

    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

  • @toxicrez1
    @toxicrez1 8 หลายเดือนก่อน

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

  • @thomasthetankcat1133
    @thomasthetankcat1133 2 ปีที่แล้ว

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

  • @fulgencejuniorlohore854
    @fulgencejuniorlohore854 9 หลายเดือนก่อน

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

  • @vicentegirardin
    @vicentegirardin 3 ปีที่แล้ว +18

    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;
    }

    •  2 ปีที่แล้ว +1

    • @kikitsunee__
      @kikitsunee__ ปีที่แล้ว +1

  • @fy8449
    @fy8449 2 ปีที่แล้ว

    Just what I needed.

  • @ZacharyAghaizu
    @ZacharyAghaizu 3 ปีที่แล้ว +2

    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?

    • @HypedCloud
      @HypedCloud  3 ปีที่แล้ว +3

      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 :)

  • @TheCurious36
    @TheCurious36 3 ปีที่แล้ว +1

    very solid video man, thanks a bunch

  • @monsterblues
    @monsterblues ปีที่แล้ว

    Thanks this was very helpful!

  • @Massive_M
    @Massive_M ปีที่แล้ว

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

  • @techwithkuda8952
    @techwithkuda8952 2 ปีที่แล้ว +1

    U just earned my sub

  • @arcanep
    @arcanep 2 ปีที่แล้ว

    Awesome! :D

  • @rachapongwatana3868
    @rachapongwatana3868 2 ปีที่แล้ว

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

  • @narsower
    @narsower 2 ปีที่แล้ว

    Thank you. You helped me how smoothly change image

  • @fc6827
    @fc6827 3 ปีที่แล้ว +1

    This was amazing, thank you.

  • @GraphicalBoss
    @GraphicalBoss 3 ปีที่แล้ว +1

    Excellent Job on your video👏👏👏👏

  • @SurpriseMotherFaker
    @SurpriseMotherFaker 2 ปีที่แล้ว

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

  • @ormedeo_fucsia
    @ormedeo_fucsia 3 ปีที่แล้ว +1

    Thank You!

  • @Firefox-hw3co
    @Firefox-hw3co ปีที่แล้ว

    Thank you so much!

  • @aureliencord5763
    @aureliencord5763 3 ปีที่แล้ว

    Very useful & clear explanation,
    Thanks !

  • @pyt3z
    @pyt3z ปีที่แล้ว

    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.

  • @touhidrabbenyshafin8471
    @touhidrabbenyshafin8471 3 ปีที่แล้ว

    Amazing!

  • @Stinger-rq4gy
    @Stinger-rq4gy 3 ปีที่แล้ว

    Excellent, love it

  • @catteixeira18
    @catteixeira18 3 ปีที่แล้ว

    Life saver!

  • @misal-isahabe5281
    @misal-isahabe5281 2 ปีที่แล้ว

    Thanks for this tutorial, it is so good content!

  • @wratio335
    @wratio335 2 ปีที่แล้ว +1

    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?

  • @sherlockholmes374
    @sherlockholmes374 ปีที่แล้ว

    I can't apply the text layer to the text frame on the camera :(

  • @RicardoADev
    @RicardoADev ปีที่แล้ว

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

  • @DahMaus
    @DahMaus ปีที่แล้ว

    THANKS YOU VERY MUCH

  • @dragonballz3686
    @dragonballz3686 2 ปีที่แล้ว +2

    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.

    • @HypedCloud
      @HypedCloud  2 ปีที่แล้ว +1

      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 :)

    • @dragonballz3686
      @dragonballz3686 2 ปีที่แล้ว +1

      @@HypedCloud yeah thanks bro

  • @tegomlee
    @tegomlee 2 ปีที่แล้ว

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

  • @guesrt2235
    @guesrt2235 3 ปีที่แล้ว

    Você é monstro!

  • @Stinger-rq4gy
    @Stinger-rq4gy 3 ปีที่แล้ว +1

    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?

    • @Lury03
      @Lury03 ปีที่แล้ว +1

      i m at the same point right now

  • @agoodbambino2181
    @agoodbambino2181 3 ปีที่แล้ว

    Hi, Great tutorial! How can make a health pickup for healing this specific health script?

  • @markiavelli
    @markiavelli ปีที่แล้ว

    Hmm but I can't put my Health Text into the Main Camera Text slot :(.

    • @markiavelli
      @markiavelli ปีที่แล้ว

      Also, you can't create a sprite anymore. It's an image now

  • @cinemacat4108
    @cinemacat4108 3 ปีที่แล้ว

    Wow very helpful

    • @HypedCloud
      @HypedCloud  3 ปีที่แล้ว +1

      Glad I could help :D

  • @코코아_Cocoa
    @코코아_Cocoa 2 ปีที่แล้ว

    Thanks :)

  • @Mrazgoodaz
    @Mrazgoodaz 3 ปีที่แล้ว +1

    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.

    • @HypedCloud
      @HypedCloud  3 ปีที่แล้ว

      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 :)

  • @yrelionne
    @yrelionne 2 ปีที่แล้ว

    Awesome tutorial but i have a problem when i click on the button the health bar doesn't reduce if someone can help me

  • @mattthegod6940
    @mattthegod6940 3 ปีที่แล้ว

    Need help, it says “The script don’t inherit a native class that can manage a script “
    Anyone knows a fix?

  • @bunbunmikey7485
    @bunbunmikey7485 3 ปีที่แล้ว

    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?

    • @HypedCloud
      @HypedCloud  3 ปีที่แล้ว +1

      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.

    • @bunbunmikey7485
      @bunbunmikey7485 3 ปีที่แล้ว

      @@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.

    • @HypedCloud
      @HypedCloud  3 ปีที่แล้ว

      @@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;

    • @bunbunmikey7485
      @bunbunmikey7485 3 ปีที่แล้ว

      @@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.

  • @kaorimiyazono2026
    @kaorimiyazono2026 4 ปีที่แล้ว +1

    thx

  • @Hurkaaa
    @Hurkaaa 3 ปีที่แล้ว

    Hi! How can I make on collision the HP is lowered by 5? (Sry for the bad eng)

    • @HypedCloud
      @HypedCloud  3 ปีที่แล้ว +1

      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 :)

    • @Hurkaaa
      @Hurkaaa 3 ปีที่แล้ว

      @@HypedCloud Thanks ^^

    • @Hurkaaa
      @Hurkaaa 3 ปีที่แล้ว

      @@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)

    • @HypedCloud
      @HypedCloud  3 ปีที่แล้ว

      @@Hurkaaa try:
      if (other.tag == “enemy”)
      Damage(5);

    • @Hurkaaa
      @Hurkaaa 3 ปีที่แล้ว

      @@HypedCloud Nope. Not working

  • @hulick6910
    @hulick6910 3 ปีที่แล้ว

    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.

  • @Lavender34124
    @Lavender34124 2 ปีที่แล้ว

    it says can't add component health cause script class cannot be found

    • @CryosBS
      @CryosBS 2 ปีที่แล้ว

      name your script Health with a capital or health

  • @vicentegirardin
    @vicentegirardin 3 ปีที่แล้ว

    how do you create the buttons

    • @HypedCloud
      @HypedCloud  3 ปีที่แล้ว

      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

  • @mixedtrigenito
    @mixedtrigenito 2 ปีที่แล้ว

    the audio is holy shit....

  • @ravenace8485
    @ravenace8485 7 หลายเดือนก่อน +1

    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.

  • @dibaterman
    @dibaterman 3 หลายเดือนก่อน

    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.

    • @dibaterman
      @dibaterman 3 หลายเดือนก่อน

      A 2x speed and 4 minutes late... welcome to the forgotten pile.

    • @dibaterman
      @dibaterman 3 หลายเดือนก่อน

      This post was on a different video... odd, I never posted on this video =/.

  • @GameDesignverse
    @GameDesignverse 3 ปีที่แล้ว

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