Easy Enemy Health Bars in Unity

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 58

  • @tgporter07
    @tgporter07 Рік тому +22

    For anybody who ran into problems with the health bar stretching when rotation is added, I was able to fix this by changing the rotation of the canvas rather than the health bar UI item itself. This is a simple fix:
    transform.rotation = camera.transform.rotation;
    becomes
    transform.parent.rotation = camera.transform.rotation;
    hope this helps some people out!

    • @animezeingamer
      @animezeingamer Рік тому

      Thank you. Went looking for this comment when I ran into the issue myself. 👍

    • @DPTecas
      @DPTecas Рік тому

      You are the man, thank you

    • @MrWebbtang
      @MrWebbtang Рік тому +1

      You are a legend, I was tearing my hair out trying to fix this. Can't believe I fell into the 'rotating a scaled transform' trap AGAIN

  • @TransGuyShane
    @TransGuyShane Рік тому +8

    I literally never thought of adding health bars directly to enemies, with its own canvas and everything 😅
    Thanks for the tutorial ♡

  • @bigp0y
    @bigp0y Рік тому +17

    It's been too long, bmo. We demand more videos!

  • @theanimationstation9644
    @theanimationstation9644 Рік тому +3

    That was short, informative , well explained….. I loved it

  • @eileeng2492
    @eileeng2492 Рік тому +3

    Hey so glad youre back.
    Love your videos

  • @mandamoon9149
    @mandamoon9149 Рік тому +6

    Clicked on this so fast 💨 Bmo is the tutorial rizzler

  • @_Garm_
    @_Garm_ Рік тому +7

    welcome back, was just wondering where you dissapared :)

  • @kimolsson8564
    @kimolsson8564 Рік тому +5

    The King strikes again!

  • @rgodoy86
    @rgodoy86 Рік тому

    Amazing tutorial. There are so many overcomplicated videos on UA-cam. You did it simple and straight to the point. Thanks!

  • @MajesticMindGames
    @MajesticMindGames Рік тому +3

    Nice, thank you for making this.

  • @SneezeAlpha
    @SneezeAlpha Рік тому +3

    You are back!

  • @linsfunbox4052
    @linsfunbox4052 6 місяців тому +1

    Very good tutorial. However, I can see the border of Canvas in game view. Not sure why. How to get rid of border of Canvas in game view?

  • @globes179
    @globes179 Рік тому +4

    Great - very good teacher

  • @pixelart0124
    @pixelart0124 10 місяців тому

    Very helpful and simple and easy, thank you so much!

    • @BMoDev
      @BMoDev  10 місяців тому +2

      Appreciate it, now go make the best game of all time

  • @Stompin40
    @Stompin40 Рік тому +6

    This is so damn helpful!!!! Thank you, thank you, thank you!!!!!!

  • @pixelsoupgames
    @pixelsoupgames Рік тому +2

    I'll keep that saved. Thanks!

  • @evilMissRune
    @evilMissRune Рік тому

    a helpful and simple video, and exactly what i was looking for. thank you

  • @iiropeltonen
    @iiropeltonen Рік тому

    Wow! You're Back! Welcome I missed your coding videos!😢❤

    • @lymincs8031
      @lymincs8031 Рік тому

      First, reference the Sprite Renderer next to the variables with "public SpriteRenderer sprite" Then, use code to change the color when the health is under a certain amount. For example, if you wanted it to turn red when under 50 health, you could write "if(health < 50)
      {
      sprite.color = red;
      }
      Hope this helped! (Also I've never actually tried it, but if I had to guess, this is how you would do it.)

  • @yuxuan130411
    @yuxuan130411 Рік тому +1

    does it ever go to zero? looks like there is always a little bit color left

  • @wob3786
    @wob3786 14 годин тому

    Works for me but leaves an annoying white square artifact i cant seem to remove

  • @ProfesserSeal
    @ProfesserSeal День тому

    I have the health bar working, but how do I make it so that the health bar stays at the top of my game scene and not move with the enemy character?

  • @shonsomech7839
    @shonsomech7839 Рік тому +1

    do you have tutorial for that shooting? it looks really good and the way it bounces :D

  • @mocheford
    @mocheford 8 місяців тому

    Hey that's a great tutorial, I will use it. A question : My enemies come from far away, how do I keep the health bar big enough to always see it ? Will it shrink as if with the distance ?

  • @danielinverso5869
    @danielinverso5869 11 місяців тому

    Also if for some reason you don't want to have a camera variable, Quaternion.identity also works fine though my project is 2D so I dont know if it works in 3D or not.

  • @Tbout72
    @Tbout72 7 місяців тому

    Why in the Canvas in the Event Camera you didn't assign the Main Camera ?

  • @Smudge04
    @Smudge04 Рік тому +1

    when it got to the rotation part, when i locked the slider in place, it just started stretching, do you know a fix for this? loved the video!

  • @guillermozafra8993
    @guillermozafra8993 7 місяців тому

    This tutorial rotates the whole object to rotate the canvas alongside it. In 3D, your whole model will be facing the floor when rotated, instead of just the model. Doing slider.transform.rotation instead of transform.rotation is an easy fix

  • @TibiaOTarena
    @TibiaOTarena 8 місяців тому

    so what if there a multiple enemies? I use pooling for them do I hvae to pool the canvas separately?

  • @Ryöken17
    @Ryöken17 4 місяці тому

    looking for you healthbar in children takes too long for the game, you could do it like your slider, drag and drop?

  • @benriffe4705
    @benriffe4705 11 місяців тому

    great video thanks bud!!

  • @AnbuBlackFro
    @AnbuBlackFro 11 місяців тому

    Getting an issue on the floating health bar script. On public void update health bar "must declare a body because it is not marked abstract, extern or partial" and on the line below at 5:04 slider, current and max value "does not exist in current context" anyone know where i went wrong 🙏🏾

  • @Cgtchilly
    @Cgtchilly Рік тому

    how do i make it fetch the cameras position on its own and not have to drag it in so when i make a enemy preset i dont have to drag it in to everyone i place down

  • @n0teroblox
    @n0teroblox 7 місяців тому

    My health bar starts at 0 and then when i shoot it, it goes to 10?

  • @Meireiyangpanmei-g8f
    @Meireiyangpanmei-g8f 3 місяці тому

    Thank you sir

  • @YusafAnimations
    @YusafAnimations Рік тому

    how to make it turn yellow and red at certain health?

  • @Ryöken17
    @Ryöken17 4 місяці тому

    We have to rotate the health bar cause you made the enemy rotate, so why rotating him ?

  • @chinesepetants2767
    @chinesepetants2767 Рік тому

    One question, if I make too many monsters by prefab in one scene, does that mean it will create tons of canvas? Is that ok?

  • @mindbodymusic21
    @mindbodymusic21 Рік тому

    Hi great video loved it small suggestion link in the description or end of video related videos

  • @MohamadNurjaman
    @MohamadNurjaman Рік тому

    i did it till the increase and decrease teh value, but when i play it, and add background sprite like Mountain or something, the hpbar was covered by the background sprite, how to fix it ?
    i already tried to put sprite renderer on the canvas but not work

    • @botcomborderreaching3518
      @botcomborderreaching3518 9 місяців тому

      Same problem, I have health bar on asteroid, but asteroid keeps blocking it

  • @FRANCOPROHOLA
    @FRANCOPROHOLA Рік тому

    Nice video man :D

  • @namk0163
    @namk0163 7 місяців тому

    Does anyone know why he uses [SerializeField] instead of the regular private access modifiers?

    • @BMoDev
      @BMoDev  7 місяців тому

      Shows up in unity inspector

  • @katkatgame
    @katkatgame 5 місяців тому

    Thank you

  • @vovanphat8040
    @vovanphat8040 Рік тому

    very very helpfull thanks you.

  • @marcosrodriguez1590
    @marcosrodriguez1590 Рік тому

    Thank you!!!

  • @superadi2774
    @superadi2774 Рік тому

    thanks a lot

  • @tapcoin5513
    @tapcoin5513 8 місяців тому

    thanks

  • @GTN2852
    @GTN2852 9 місяців тому

    My game Helth bar app avalable

  • @zaidalfayyadh_2537
    @zaidalfayyadh_2537 Рік тому

    Great tutorial!! subscribe.

  • @sourirerouge9995
    @sourirerouge9995 2 місяці тому

    ty ty

  • @johnnygamer4933
    @johnnygamer4933 Місяць тому

    You made the Slider slider private, and the you instantiate from unity...
    that's cheating.

  • @zote1
    @zote1 3 місяці тому +1

    here is the code if anyone wants it remamber change the name the
    one you are using
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    public class FloatingHealthBar : MonoBehaviour
    {
    [SerializeField] private Slider slider;
    [SerializeField] private Camera camera;
    [SerializeField] private Transform target;
    [SerializeField] private Vector3 offset;
    public void UpdateHealthBar(float currentValue, float maxValue)
    {
    slider.value = currentValue / maxValue;
    }
    void Update()
    {
    transform.rotation = camera.transform.rotation;
    transform.position = target.position + offset;
    }
    }