Topic was automatically imported from the old Question2Answer platform.
Asked By
brazmogu
I want to attach some UI elements to my 2D actors so I can have, for example, a health bar floating over my units. Is there a correct way to make my Control node’s position follow my actor’s position (which is what I think Unity refers to as “World Space UI”)?
Just make your Control(s) a child of the actor. It will follow automatically. If your actor rotates, you can reset the global_rotation manually to compensate.
Well, that was unexpectedly simple XD Anchoring it is a bit harder than it seems, but it does work…
Follow-up question: can a UI element be drawn behind the rest of the stuff in the game? I can’t find any Z field in the control nodes, and using a Canvas Layer is just making the element disappear
brazmogu | 2020-03-19 02:52
I’m currently facing this problem, and with this solution the HUD elements (health bar, etc) will appear behind other actors in the game. I’m working out a way to use CanvasLayer to make all the HUD elements appear in a separate layer above the game actors, while still following them.
Another idea is if your camera moves sepratly from the player would be to put the ui in a separate canvas layer, this would also make it so that if your in a dark room you would still be able to see your ui.