Place UI Elements in your World! (Health Bar, Overlays, Timers)

Поділитися
Вставка
  • Опубліковано 17 лип 2024
  • Let's learn how we can use UI Elements in the game using a World Space Canvas! 👇
    🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses
    👍 Learn to make awesome games step-by-step from start to finish.
    🌍 Get Code Monkey on Steam!
    👍 Interactive Tutorials, Complete Games and More!
    ✅ store.steampowered.com/app/12...
    If you have any questions post them in the comments and I'll do my best to answer them.
    🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
    See you next time!
    📍 Support on Patreon / unitycodemonkey
    🤖 Join the Community Discord / discord
    📦 Grab the Game Bundle at unitycodemonkey.com/gameBundl...
    📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
    #unitytutorial #unity3d #unity2d
    --------------------------------------------------------------------
    Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
    I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
    You can see my games at www.endlessloopstudios.com
    --------------------------------------------------------------------
    - Website: unitycodemonkey.com/
    - Twitter: / unitycodemonkey
    - Facebook: / unitycodemonkey

КОМЕНТАРІ • 83

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  3 роки тому +4

    🌐 Have you found the videos Helpful and Valuable?
    ❤️ Get my Courses unitycodemonkey.com/courses or Support on Patreon www.patreon.com/unitycodemonkey

  • @Sephta
    @Sephta 3 роки тому +17

    I kid you not when I say I literally was researching this topic a day before this videos release. Your timing is immaculate!

  • @MohamedMagdy-ql3pl
    @MohamedMagdy-ql3pl 3 роки тому +13

    Interestingly enough, it looks like literally everyone has been looking for this yesterday. Looking forward to more UI tutorials!

  • @diogomuller8089
    @diogomuller8089 3 роки тому +3

    I literally needed this right now, thank you so much!

  • @arcday4281
    @arcday4281 3 роки тому

    Your channel is getting better every day ! At the expense of my obsessive theme "Ways to Reference GameObjects" I mean: hook-up, FindObjectOfType, Singleton, ScriptableObject, Dependency Injection ... I hope you will add this either in a separate video, or in the advanced" C# "in " Steam". I think it will be useful for beginners to understand your code even better. Especially the methods you use in your code. Some things were not clear to me personally. Perhaps I missed something and did not see the explanation on this topic )))

  • @neozoid7009
    @neozoid7009 2 роки тому

    Awesome Thanks CM again , This was a very helpful information

  • @pauls.7663
    @pauls.7663 3 роки тому +3

    Omg. This is exactly what i need! I experimented with that yesterday! :P

  • @_shon3266
    @_shon3266 3 роки тому

    Great tutorial)
    I always used slider for healt bar, now i know about Fil Method in Image^^

  • @omar-0082
    @omar-0082 6 місяців тому

    thank you very much its much simple that i excepted !

  • @Nick-rq4gy
    @Nick-rq4gy 3 роки тому

    This is great, seen it so good.

  • @MasterBroNetwork
    @MasterBroNetwork 3 роки тому +2

    Figured out my own fix for the scaling issue, I set it to Screen Space - Camera, designed the UI and then set it to World Space, it fixed the issues I had with it.

  • @muntasirchowdhrymridul64
    @muntasirchowdhrymridul64 3 роки тому +3

    So, I was watching your video and suddenly an ad came up. Guess what! it was an ad for your own course! You got an ad for your course in your own video XD
    it's like paying yourself XD
    anyway, thanks for such an awesome video.

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  3 роки тому +7

    💬 Here's a simple video on a very useful feature.
    For example I used this in making my recent Racing RTS for making all the UI in the game on top of the Player's car.

  • @ibmagar6188
    @ibmagar6188 2 роки тому

    Very awesome tutorial

  • @jean-michel.houbre
    @jean-michel.houbre 3 роки тому

    Nice video, thanks.

  • @leonardo6631
    @leonardo6631 3 роки тому

    Great video!

  • @DJM3D
    @DJM3D 3 роки тому

    Hello there, I'm having issues with world space canvas rendering. It's in a 3D game and it's rendering on top of everything. It's supposed to just be on a screen but when I leave the room it shows through everything. Can't think of anything to do to fix this, aside from not using UI materials. Any help?

  • @nyscersul42
    @nyscersul42 2 роки тому

    Helpful!

  • @vijayathaker552
    @vijayathaker552 3 роки тому +1

    Sir I need some serious help in unity 3d health bar. I made health bars for enemy in unity 3d working perfect but the problem is with the size. Suppose I am looking at the enemy from a point and the health bar looks perfect but when the enemy comes near me the health bar size grows, I want to do something from which the health bar seems to just move and not getting larger on coming near the camera. I want it to look like its floating there but while coming near the camera its size increase and going away decrease. Can anyone help me if u understood?

  • @kennysrael2288
    @kennysrael2288 3 роки тому

    I think sprite objects has polygons in it, when you look at wireframe mode, so maybe that affects the performance. I'm not 100% sure thougb

  • @matthiasVO
    @matthiasVO 3 роки тому +1

    You should make a tuturial on how to make your game multiplayer. (mobile) would really help me out

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

    So i already implemented a WorldSpace health bar for my enemies. How can i reveal their position?
    I just want to display a small icon above their head and i want that icon to not be blocked by GameObjects. It's kidna like a "object marker" thing which always visible regarding from the distance.

  • @leonardocafissi5580
    @leonardocafissi5580 3 місяці тому

    I have a problem, I have to create a smart glasses, I want to show ui wordspace of some people only in the glass of the glasses, I try to use sprite mask (but it works only with objects not with ui element) or ui mask (but it hides only the children of ui element with this component), how can I do this? sorry for my bad english

  • @RaulKFernandes
    @RaulKFernandes 2 роки тому

    Hey there, nice approach on this! I was trying to replicate all that for a test but on my world space canvas sorting layer there was no "Top" or other options then "Default". I need to implement an onboarding where a 'hand' UI Image appears in world space to animate between two positions in a loop, but also to render in front of the other objects. That "Top" sorting layer would cover this? How did u set it? If not, do u know another way that i could implement this approach? Anyways, thanks for you content :)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому +1

      You can create as many sorting layers as you want and order them unitycodemonkey.com/video.php?v=5_BwFB-1dAo

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

    I try to create a 2d game and use Y axis transparency sort mode, when i add health bar UI in my character their pivot are dissimilar, sorting group can't group UI elements like other gameobjects. Can you help me?

  • @tauheedgamedev2388
    @tauheedgamedev2388 3 роки тому +1

    Im one step closer to building my dream RTS game.

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

    ty. I was confused as to why text always spawned with Canvases.

  • @wendten2
    @wendten2 3 роки тому +1

    in 3D, if you want your world space canvas to have a 2D look (looking at the camera) how do you achieve that? doing the rotation in the update seems a bit bad performance wise

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому +4

      You do have to rotate as much as your camera moves so probably on every Update
      It's just a simple script on the Canvas with a transform.LookAt(cameraTransform.position);
      That's a pretty fast operation so it's unlikely to end up as a performance issue.

    • @RecOgMission
      @RecOgMission 3 роки тому

      I've used this. I create UI elements on the canvas and, in my camera controller, I call the rotation method whenever the camera rotates, instead of each frame. I also resize the UI elements based on camera zoom, so they are still visible when zoomed way out, and shrink to not take over the screen when zooming in.

  • @sundarakrishnann8242
    @sundarakrishnann8242 3 роки тому +1

    Hi in the prefab editing mode the prefab is bright and looks as expected but on dragging the prefab model in to the 3d scene it becomes too dull! I think it is because of the lighting? Is that the only reason or is there anything else? Also one part of the model is darker than the other mostly due to lighting, could you please make some videos on 3d lighting and polishing the scene, I dont know anything about lighting....Also please suggest some quick tips and things that I have to follow to have a good lighting! Thanks !

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому +1

      In Prefab editing mode I think the lighting is essentially unlit, so it gets light from everywhere.
      On the actual scene it depends on your directional light and any others you have.
      Lighting is definitely a very tricky subject, you just have to keep iterating and playing with all parameters. Change the intensity, color, ambient light, baking settings, etc.

    • @sundarakrishnann8242
      @sundarakrishnann8242 3 роки тому +1

      @@CodeMonkeyUnity oh okay! Thanks a lot! I shall look into it and play with the values!

  • @hondayadav9527
    @hondayadav9527 3 роки тому

    awesome

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

    How to handle text? Appears hard to scale. I can get text to show correctly scaled using 'scale' on the text, but seems messy. Wondering if there is a standard solution for this? (scale the canvas perhaps?)

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

      You can indeed play around with the scale, either the Text object itself or the Canvas. Although personally I normally tend to modify the text font instead.

  • @QvsTheWorld
    @QvsTheWorld 3 роки тому

    I have 2 question. How would I manage the rotation so that le ui element is always facing the camera straight on. Secondly in the case of the wall I would always want the health bar to be between the wall and the camera and still shrink from view while walking away.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому +1

      You can make a simple script that just does transform.LookAt(cameraTransform.position);
      If you always want it on top then you can use layers and a custom render objects feature

  • @samirkazah302
    @samirkazah302 3 роки тому

    Highly underrated feature

  • @UnRATel
    @UnRATel 6 місяців тому

    i am currently trying to add Damage Popups to my spawned Monster (i already watched your other video about Damage Popup) my problem is that i am using Screen Space - Overlay for my project and i can't get it done spawning these when they get damage right above their head (with animations). If i got that right for UI i need to use "TextMeshPro - Text (UI)" and this inside a Canvas. I instantiate the DamagePopup with the same Transform as the Monster and additionally set my MainCanvas as parent (so it gets spawned inside)... but this doesn't really seem to work :/ hope for help

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 місяців тому

      Not sure I understand your question, your main Canvas can indeed be Screen Space Overlay, and then for the damage popups you can put each of them inside a Canvas and make it World Space, then position that canvas wherever you want

  • @DjCtavia
    @DjCtavia 3 роки тому

    Lovely accent, nice tut.!

  • @bhautikranpara7664
    @bhautikranpara7664 3 роки тому

    sir there is only one tutorial of autoverb in unity so plz make video on it with detail as you are making in your every videos

  • @L1ghtOn3
    @L1ghtOn3 2 роки тому

    My UI Keeps getting cut off behind the terrain, any ideas to bring the UI in front of the terrain, it looks terrible when playing and the controls which are touch get lost as well depending on which side I pan when looking around, you would think unity would have the UI in front of everything? Thank you

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      If you want the UI on top of everything then use a regular Screen Space canvas, not a World Space canvas.
      The World Space canvas is exactly meant for it to be occluded by world objects in front of it.

    • @L1ghtOn3
      @L1ghtOn3 2 роки тому

      @@CodeMonkeyUnity I have my canvas on screen space camera. I fixed it by puting the plane distance from 1 to 0.25, my pause menu to 0.25 abd ny gameover canvas to to 0.24, The main UI with my all my UI like health and rouch controls works from 0.23 - 0.26 anything higher it starts to move behind the terrain. I feel 0.25 is fine, I need the GameOver to cover the main UI so it goes to 0.24 and the Pause menu works on 0.25, I thought about 0.24 but tangles with the GO canvas, bizzare, still woking all this iut since its on screen space canera, not overlay or world. So far so good, really did not like the UI health etc disappearing behind the terrain at times but works now yipee, thanks for the reply and maybe ive helped someone else? Who knows. Cheers ✌

  • @pedravoadora2230
    @pedravoadora2230 2 роки тому

    There is only one thing that i still can't make work. I can't make texts small enough, the font size cannot go below 1. Do you have any ideas on how to do it? Thanks!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      Interesting, I've never tried going under 1 but I assumed it would work
      I guess you can maybe play with the scale, put the canvas scale on something like .1, .1, .1 or maybe the text object itself

  • @GRAVITONIX
    @GRAVITONIX 3 роки тому

    Nicee

  • @omiorahman6283
    @omiorahman6283 3 роки тому

    It looks attractive

  • @mechworriorsmasterstreams6608
    @mechworriorsmasterstreams6608 3 роки тому

    Please sir make tutorial on c## language too.

  • @AnAn-nh9nd
    @AnAn-nh9nd 3 роки тому

    can you make a level unlocking system tut?
    or u already made 1

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому

      Not sure what you mean by that, I made a Level System ua-cam.com/video/kKCLMvsgAR0/v-deo.html

    • @AnAn-nh9nd
      @AnAn-nh9nd 3 роки тому

      @@CodeMonkeyUnity like when you complete a level(aka a stage) it unlocks a new one

  • @TheYuuuk
    @TheYuuuk 3 роки тому

    Can you to teach how to render 3D models (can rotate) in UI Elements?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому

      Hmm I think if you just position the object on the UI layer as a child of the Canvas
      Or make the UI with a Camera instead of Screen Space and it should work

  • @FractalIND
    @FractalIND 3 роки тому

    do you wknow a way to make the UI overly in 3D, ik i can use worldtoscreenpoint, but i need the scale so hat it looks like i am getting farther or closer

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому

      Using this world space canvas is how you do it, it's an object in the world so as you move in it gets bigger, what else do you need? How to interact with it? I covered that Cyberpunk Remake video for interacting with an ATM ua-cam.com/video/pIzWlfbVORU/v-deo.html

    • @FractalIND
      @FractalIND 3 роки тому

      @@CodeMonkeyUnity i wanted to make the 3D Ui in the canvas to be on top of everything, i figured it out

    • @jz3r073
      @jz3r073 2 роки тому

      @@FractalIND how

    • @FractalIND
      @FractalIND 2 роки тому

      @@jz3r073 i dont think i have the project anymore, ill look in the morning cuz its like 2 AM 🙃

    • @jz3r073
      @jz3r073 2 роки тому

      @@FractalIND bro, thanks so much, but I finally figured out, no problem my men, go to sleep hahaha

  • @redoctober2088
    @redoctober2088 2 роки тому

    My 2D player rotates. How do I freeze the health bar rotation, so it's always above the player?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      Add a simple script to set the transform.eulerAngles to 0,0,0 on LateUpdate

    • @redoctober2088
      @redoctober2088 2 роки тому

      @@CodeMonkeyUnity Okay, thank you!

  • @ryanyuri980
    @ryanyuri980 3 роки тому

    Make a collab with Josh of Let's Game It Out, please

  • @halivudestevez2
    @halivudestevez2 6 місяців тому

    how to make the canvas look towards the camera?

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

      Easiest way is just make a simple script that does transform.LookAt(Camera.main.transform);
      Alternatively transform.forward = Camera.main.transform.forward; or transform.forward = -Camera.main.transform.forward;

    • @halivudestevez2
      @halivudestevez2 6 місяців тому

      thank you for the answer! (I've also found a Look at constraint, ready-made component by unity, when I tried to add mine)

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

    sos god

  • @Deadwindshadow
    @Deadwindshadow 3 роки тому

    I use sliders for health ;)

  • @d1kiywolf
    @d1kiywolf 2 роки тому

    Guys, what if i need to press a button in the world space? I cant press it at all

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      You can do a Raycast yourself, I made interactable UI buttons here unitycodemonkey.com/video.php?v=pIzWlfbVORU

  • @Stnaire
    @Stnaire 4 місяці тому

    So you create a canvas for each unit? Seems really inefficient.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 місяці тому

      It all depends on your use case. Perfect fine if you have a dozen, not fine if you need thousands.

  • @iwoMalki
    @iwoMalki 3 роки тому

    I want to be your padawan....

  • @AgastyaWrites1
    @AgastyaWrites1 3 роки тому

    Hi

  • @andreb5466
    @andreb5466 14 днів тому

    nem em 0.25x eu consigo ver direito o que é selecionado. aí complica. Parabéns pelo vídeo, mas não dá para assistir.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  13 днів тому

      Qual parte não consegues seguir? Cria um Canvas e poe como World Space, é so isso

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

    try make the video for beginner. i dont like your approach