Three Cool Health Bars in Unity (2022/2020)

Поделиться
HTML-код
  • Опубликовано: 20 сен 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 2 года назад +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 5 месяцев назад

    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 6 месяцев назад

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

  • @vicentegirardin
    @vicentegirardin 3 года назад +19

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

  • @TheCurious36
    @TheCurious36 3 года назад +1

    very solid video man, thanks a bunch

  • @GraphicalBoss
    @GraphicalBoss 3 года назад +1

    Excellent Job on your video👏👏👏👏

  • @fy8449
    @fy8449 2 года назад

    Just what I needed.

  • @rachapongwatana3868
    @rachapongwatana3868 2 года назад

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

  • @fc6827
    @fc6827 3 года назад +1

    This was amazing, thank you.

  • @techwithkuda8952
    @techwithkuda8952 2 года назад +1

    U just earned my sub

  • @narsower
    @narsower 2 года назад

    Thank you. You helped me how smoothly change image

  • @SurpriseMotherFaker
    @SurpriseMotherFaker 2 года назад

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

  • @aureliencord5763
    @aureliencord5763 3 года назад

    Very useful & clear explanation,
    Thanks !

  • @Massive_M
    @Massive_M Год назад

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

  • @monsterblues
    @monsterblues Год назад

    Thanks this was very helpful!

  • @ormedeo_fucsia
    @ormedeo_fucsia 3 года назад +1

    Thank You!

  • @misal-isahabe5281
    @misal-isahabe5281 2 года назад

    Thanks for this tutorial, it is so good content!

  • @Stinger-rq4gy
    @Stinger-rq4gy 3 года назад

    Excellent, love it

  • @arcanep
    @arcanep 2 года назад

    Awesome! :D

  • @Firefox-hw3co
    @Firefox-hw3co Год назад

    Thank you so much!

  • @RicardoADev
    @RicardoADev Год назад

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

  • @touhidrabbenyshafin8471
    @touhidrabbenyshafin8471 2 года назад

    Amazing!

  • @BrawlMouse.
    @BrawlMouse. Год назад

    THANKS YOU VERY MUCH

  • @tegomlee
    @tegomlee 2 года назад

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

  • @cinemacat4108
    @cinemacat4108 3 года назад

    Wow very helpful

  • @catteixeira18
    @catteixeira18 2 года назад

    Life saver!

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

  • @guesrt2235
    @guesrt2235 2 года назад

    Você é monstro!

  • @코코아_Cocoa
    @코코아_Cocoa 2 года назад

    Thanks :)

  • @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?

  • @kaorimiyazono2026
    @kaorimiyazono2026 3 года назад +1

    thx

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

  • @hulick6910
    @hulick6910 2 года назад

    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.

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

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

  • @agoodbambino2181
    @agoodbambino2181 3 года назад

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

  • @sherlockholmes374
    @sherlockholmes374 Год назад

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

  • @charlesdelachapelle2113
    @charlesdelachapelle2113 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

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

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

  • @mattthegod6940
    @mattthegod6940 3 года назад

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

  • @Lavender34124
    @Lavender34124 2 года назад

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

    • @CryosMC
      @CryosMC Год назад

      name your script Health with a capital or health

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

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

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

  • @dibaterman
    @dibaterman 23 дня назад

    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 23 дня назад

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

    • @dibaterman
      @dibaterman 21 день назад

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

  • @ravenace8485
    @ravenace8485 4 месяца назад +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.

  • @GameDesignverse
    @GameDesignverse 2 года назад

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