HOW TO MAKE A SIMPLE HEALTH BAR IN UNITY! Unity 2D Tutorial

Поделиться
HTML-код
  • Опубликовано: 29 авг 2024
  • In this video I'll show you a quick and simple way to create a HEALTH BAR in Unity!
    Check out my previous 1 minute tutorials: • UNITY TUTORIALS
    if there are any tutorials you'd like to see, feel free to leave a comment below!
    ------------------------------
    Follow me on TWITTER: / jakemakesgames
    The music found in this video: • Video
    (no copyright is intended by using this music, all rights go to their respective creators).
    ------------------------------

Комментарии • 136

  • @Snailerino
    @Snailerino 10 месяцев назад +10

    When i try to run it, it says "The type or namespace name 'image' could not be found. What can I do to fix it?

    • @JakeMakesGames
      @JakeMakesGames  10 месяцев назад +7

      Be sure to include ‘using UnityEngine.UI;’ at the top of the script

    • @GumbiOfficial
      @GumbiOfficial 9 месяцев назад +3

      @@JakeMakesGames make this top comment, (you forgot to mention it in the video)

    • @JakeMakesGames
      @JakeMakesGames  9 месяцев назад +1

      @@GumbiOfficial thank you for mentioning that!

    • @usuarion1611
      @usuarion1611 3 месяца назад +2

      @@GumbiOfficial Minute 0:45

  • @drmarx123
    @drmarx123 11 месяцев назад +14

    Best tutorials are simple and short, giving you a glimpse on how to get started. Thanks for this, other content creators would wrap this in a AAA tutorial which require you to watch it all to find the solution you are looking for.

    • @JakeMakesGames
      @JakeMakesGames  11 месяцев назад +7

      Thank you, the main reason I did the 1 min tutorials was because I was sick of watching long videos that had a bunch over fluff in them

  • @LumpAbundance
    @LumpAbundance Год назад +9

    Thank you so much for the quick tutorial. I'm so surprised how easy it is to make a game.

  • @Sir_Ninonino
    @Sir_Ninonino 7 месяцев назад +3

    Straight and simple. And best part is you can use this with your own images (which I did in my case). Thanks!

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

    MY BOY HAS BEEN CRUSHING THEM OUTTTTTTTTTT

  • @emiarty
    @emiarty 5 месяцев назад +3

    0:15 I do not have a "Square" or a "Circle" on the source image selection part. I have the rest of them. How can I get the Square option?

    • @JakeMakesGames
      @JakeMakesGames  5 месяцев назад +1

      You can navigate to the package manager and install the “2D” package, this should include everything; if not you can just import your own white square sprite and that should do the job!

  • @hellopeople2395
    @hellopeople2395 5 месяцев назад +2

    Nice video but you may want to include
    if( healthamount < 100)
    {
    healthamount = 100;
    }
    to prevent people gaining ghost health :)

  • @MSStudio00
    @MSStudio00 2 месяца назад +2

    Great video, thanks for help!

  • @orileshem486
    @orileshem486 3 месяца назад +1

    Amazing tutorial saved me hours of video watching!!!!

    • @JakeMakesGames
      @JakeMakesGames  3 месяца назад

      Thanks for the kind words! I’m glad it helped!

  • @stuartmarsh5574
    @stuartmarsh5574 7 месяцев назад +1

    Thank you I enjoyed this video, I wish you would talk a litte slower and explain a little bit of the "why" on some of the steps just so we could learn more and it would be easier for non native English speakers.

    • @JakeMakesGames
      @JakeMakesGames  7 месяцев назад +1

      Thanks for the feedback! I’ll keep that in mind for the next tutorial!

  • @Ferenc-Racz
    @Ferenc-Racz Месяц назад +1

    Short.. Old.. BUT very very useful video! Thank you for it!

  • @TDog3775
    @TDog3775 6 месяцев назад +1

    Worked like a charm! Thank you very much

  • @blazerhm
    @blazerhm 2 года назад +2

    Another awesome video

  • @StickyLabDev
    @StickyLabDev Год назад +3

    this is what i want ,thanks

  • @RootsOf7
    @RootsOf7 Месяц назад +1

    when I set it to game view the ui doesn't show up, however it does if I set the render mode to world space

    • @JakeMakesGames
      @JakeMakesGames  Месяц назад +1

      Made sure on the “canvas scaler” component “ui scale mode” is set to “scale with screen size”, that may help your issue!

    • @RootsOf7
      @RootsOf7 Месяц назад +1

      @@JakeMakesGames thanks you! I realized now that the canvas scales to the screen already and doesn't need to be within the camera. I thought I had to keep the images within the camera to see it in game 😓

    • @JakeMakesGames
      @JakeMakesGames  Месяц назад +1

      @@RootsOf7 thats odd.. if you create them as UI images as a child of the canvas, it should be fine

  • @myth6628
    @myth6628 3 месяца назад +1

    easy and short thank you

  • @NoobProMaster01
    @NoobProMaster01 Год назад +2

    Thank you for this tutorial but i have a question is how to use this health bar for my player take damage when being attack by enemy?

    • @JakeMakesGames
      @JakeMakesGames  Год назад +1

      In on trigger enter (or how ever you’re handling collisions) you need to check if the enemy collided with the player and then get reference to player health script then you’ll be able to call the take damage function

  • @matthewwilliamsvideos
    @matthewwilliamsvideos 14 дней назад +1

    Bro went at super sonic speeds💀

    • @JakeMakesGames
      @JakeMakesGames  14 дней назад +1

      That’s the point of 1 minute tutorials I guess. Quick and straight to the point

    • @matthewwilliamsvideos
      @matthewwilliamsvideos 14 дней назад +2

      @@JakeMakesGames I like it. I can tell you know your stuff

    • @JakeMakesGames
      @JakeMakesGames  12 дней назад

      Thank you I really appreciate that!

  • @CS2ClownCrew
    @CS2ClownCrew 4 месяца назад +1

    when I press play the Health Amount constantly increases, however, when I disabled the heal part of the script this stopped but I would still want the healing part to work... any ideas?

    • @JakeMakesGames
      @JakeMakesGames  4 месяца назад

      Check to see how the heal function is being called. If it’s being called in update without and checks it’s going to increase constantly

  • @drmini7522
    @drmini7522 Год назад +2

    what do i do when it says 'Application' does not contain a definition for 'LoadedLevel'

    • @JakeMakesGames
      @JakeMakesGames  Год назад +1

      That means the function ‘LoadedLevel’ doesn’t exist as an extension of ‘Application’. Rewatch that part of the tutorial, hope this points you in the right direction

  • @benriffe4705
    @benriffe4705 8 месяцев назад +1

    thanks showed me what i needed :D

  • @eduardomarinho7887
    @eduardomarinho7887 Год назад +1

    When I create the "image" component and select square, my health bar doesnt show anything, like if it was invisible. When I create a sprite and try to make it bigger, only the collision box get bigger and not the sprite

    • @JakeMakesGames
      @JakeMakesGames  Год назад +1

      make sure there is a sprite in the image component

  • @eszti0423
    @eszti0423 9 месяцев назад +1

    It's possibly that I missed something but when I click on source image to select a Sprite, I can't find square. Do I need to download it from somewhere?

    • @JakeMakesGames
      @JakeMakesGames  9 месяцев назад

      You can either import your own, or if it is missing from Unity you may need to install the 2D package from the package manager

    • @deadlockyt3644
      @deadlockyt3644 8 месяцев назад +1

      i can't find it either, u can right click in the project window, Create => 2D => Sprites => Square. Then drag the square sprite u just created into the source image spot and it should work just fine

  • @Tresto_XD
    @Tresto_XD Год назад +2

    Thanks brooo Good tutorial + new Sub

  • @imadftatchi5647
    @imadftatchi5647 Год назад +2

    how do i reference the takedamage to do actual damage?? from a enemy

    • @JakeMakesGames
      @JakeMakesGames  Год назад +4

      A quick way of doing this is ensuring the health manager is a singleton; so at the top of the health manager script:
      Public static HealthManager instance;
      void Awake()
      {
      instance = this;
      }
      And then in the enemy script in the function you’re checking with collisions with the player
      HealthManager.instance.TakeDamage(damage varable here);

  • @200anxy
    @200anxy 8 месяцев назад +1

    Hi there, @JakeMakesGames, when I do this, right after i make the canvas, these white lines show up, in the middle of the canvas, on the rendering screen. How do we prevent this?

    • @JakeMakesGames
      @JakeMakesGames  8 месяцев назад

      The only thing I can think it would be is that you have gizmos turned on in the game view

    • @200anxy
      @200anxy 8 месяцев назад +1

      @@JakeMakesGames thanks so much! that fixed my problem!

    • @JakeMakesGames
      @JakeMakesGames  8 месяцев назад

      @Axy200 you’re welcome! Those gizmo lines will only appear in the engine and aren’t rendered in the final build

  • @dtayt1
    @dtayt1 Год назад +1

    it says The type or namespace name image could not be found

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

      To need to add “using UnityEngine.UI” at the top of the script to get access to the UI elements in code

  • @capicoua
    @capicoua Год назад +1

    i have stumbled upon a problem. it says that 'float' does not contain definiton for fillAmount on some lines of code in your script. i will be grateful if someone wants to help me

    • @JakeMakesGames
      @JakeMakesGames  Год назад +1

      It’s because float doesn’t contain that. The healthbar variable that uses that line of code should be an image

  • @unston
    @unston 2 дня назад +1

    How do i connect my health bar to my player?

    • @unston
      @unston 2 дня назад +1

      I managed to do that, but my health bar goes behind my platforms, so how do I work it out?

    • @JakeMakesGames
      @JakeMakesGames  2 дня назад

      That’s odd, if it’s a standard UI canvas it should be displaying above everything. How is your canvas set up, screen or world space?

    • @unston
      @unston День назад +1

      @@JakeMakesGames It is in world space so that i can link it to my player

    • @JakeMakesGames
      @JakeMakesGames  День назад

      You’d have to look into the sorting layers

  • @grimez7869
    @grimez7869 2 года назад +2

    banger song

  • @AlexanderHallgren
    @AlexanderHallgren Год назад +5

    Great tutorial, however its impossible to follow along in a nice pace, always have to rewind and pause since you're speedrunning while talking lol..

    • @JakeMakesGames
      @JakeMakesGames  Год назад +1

      Thanks for the feedback! I’ll keep that in mind when I work on a new tutorial

    • @gideonjordan62
      @gideonjordan62 4 месяца назад +1

      Just slow it down

    • @JakeMakesGames
      @JakeMakesGames  4 месяца назад +1

      I do get that, but the idea of the “1 minute tutorials” is for them to be quick and to the point.

  • @OpxGames
    @OpxGames 8 месяцев назад +2

    i got this
    Non-invocable member

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

    When I click the return key ONCE, the health goes down to the bottom and resets the scene. Please Help!

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

      Make sure the input check is getkeydown and not just getkey

  • @PK-se2jh
    @PK-se2jh 2 года назад +1

    thankyouuuu :)

  • @Iiiiii9998
    @Iiiiii9998 Месяц назад +1

    dont see image type

    • @JakeMakesGames
      @JakeMakesGames  Месяц назад

      you need to ensure your UI image has a sprite in order to see that option

    • @Iiiiii9998
      @Iiiiii9998 Месяц назад +1

      @@JakeMakesGames Thanks, now i see it

    • @JakeMakesGames
      @JakeMakesGames  Месяц назад +1

      @@Iiiiii9998 no worries!

  • @DanteMDTNS
    @DanteMDTNS 6 месяцев назад +1

    Image has no attribute fillAmount?

    • @JakeMakesGames
      @JakeMakesGames  6 месяцев назад

      once you have dragged in a sprite for the “Source Image” a drop-down with the name “Image Type” will appear. Click that drop-down and select “Filled”

    • @DanteMDTNS
      @DanteMDTNS 6 месяцев назад

      @@JakeMakesGames i know i found this, too, but i still cannot access it in the code then. I came to the solution to use a slider which was easier for me

    • @JakeMakesGames
      @JakeMakesGames  6 месяцев назад

      That’s very strange? Glad you found a solution that works for you!

    • @DanteMDTNS
      @DanteMDTNS 6 месяцев назад

      Maybe because I'm using vsc. I didn't look if it compiles. But thanks anyway, good video =)

    • @maxgordon3194
      @maxgordon3194 2 месяца назад

      @@JakeMakesGames fillAmount doesnt work anymore sadly. the new using directive is used now. using UnityEngine.UIElements. R.I.P using UnityEngine.UI;

  • @GoatVibez637
    @GoatVibez637 6 месяцев назад +1

    I copied your exact code and now I have 24 errors
    Please tell me what I did wrong

    • @JakeMakesGames
      @JakeMakesGames  6 месяцев назад

      I can’t really help you without knowing what errors you had

    • @GoatVibez637
      @GoatVibez637 6 месяцев назад

      @@JakeMakesGames The fact you actually replied Is astonishing to me, even tho this video was made months ago

    • @JakeMakesGames
      @JakeMakesGames  6 месяцев назад

      @@GoatVibez637 I try to reply to every comment when I can! What issues are you having?

    • @GoatVibez637
      @GoatVibez637 6 месяцев назад

      @@JakeMakesGames
      There were red squiggly lines under almost every single program I wrote

    • @JakeMakesGames
      @JakeMakesGames  6 месяцев назад

      @GoatVibez312 what did the errors in the console say?

  • @lukascaha1429
    @lukascaha1429 9 месяцев назад +1

    Nice tutorial, but im lost how to make the damage on collision with enemy. I tried to do simple if tag player collides with tag enemy, it TakeDamage(20);. But that aint work. Do i need to make script for the enemy or add something more

    • @JakeMakesGames
      @JakeMakesGames  9 месяцев назад

      For that to work, both the player and enemies need a collider of some sort and at least one of them need a rigidbody.

  • @user-hy1xm6ss9l
    @user-hy1xm6ss9l 2 месяца назад +1

    my unity keeps crasing

    • @JakeMakesGames
      @JakeMakesGames  Месяц назад

      Not sure if it’s due to compiler errors or your machine? Are you getting any errors?

  • @bit7937
    @bit7937 7 месяцев назад +1

    i really needed to put this to 0.5 speed to see whats going on do lil slower next time and btw didnt work

    • @JakeMakesGames
      @JakeMakesGames  7 месяцев назад

      thanks for the feedback. Did you get any errors in the console to indicate why it wasn’t working?

  • @user-zu7zz6om2v
    @user-zu7zz6om2v 5 месяцев назад +1

    dont have the square sprite

    • @JakeMakesGames
      @JakeMakesGames  5 месяцев назад

      You can either import your own or import the 2d package from the package manager

    • @user-zu7zz6om2v
      @user-zu7zz6om2v 4 месяца назад +1

      @@JakeMakesGames I got the sprite but now the health bar wont go down, it does kill the sprite but dosnt vissualy go down

    • @JakeMakesGames
      @JakeMakesGames  4 месяца назад

      @@user-zu7zz6om2v ensure the image
      Ui components “image type” variable is set to “filled”, hope this helps

    • @user-zu7zz6om2v
      @user-zu7zz6om2v 4 месяца назад +1

      @@JakeMakesGames thx works now, best tutorials not 10 hours long

    • @JakeMakesGames
      @JakeMakesGames  4 месяца назад

      @@user-zu7zz6om2v glad you got it working! I appreciate it

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

    u should put the script in the discription

  • @BlueMoShorts
    @BlueMoShorts Год назад +1

    are you doing a speed run or something?

    • @JakeMakesGames
      @JakeMakesGames  Год назад +5

      nope, just like making tutorials that are short and straight to the point without 10 minutes of fluff in the video

    • @BlueMoShorts
      @BlueMoShorts Год назад +1

      @@JakeMakesGames lol i had to watch it frame by frame to see what you were doing

    • @JakeMakesGames
      @JakeMakesGames  Год назад +1

      @@BlueMoShorts did it work once you followed it?

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

      @@JakeMakesGames it did but it was annoying you can still make it short but easier to follow

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

    I can't find fill button can anyone help

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

      On the “image type” drop-down on the UI Image you can click that and it’ll give you some options. Fill is there

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

      @@JakeMakesGames there isnt a image type dropdown menu tho

    • @JakeMakesGames
      @JakeMakesGames  Год назад +1

      Time stamp 0:13, once you give the image component a “source image” it appears as an option

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

      @@JakeMakesGames yep got it thanks

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

    where's the code

    • @JakeMakesGames
      @JakeMakesGames  Год назад +3

      It’s not online anywhere, just follow along with the tutorials.. that’s kinda the whole point of them

  • @HamzaGaddas
    @HamzaGaddas Год назад +1

    HELP!!!!!!!!

  • @rusurobert4917
    @rusurobert4917 2 месяца назад

    satana