Y
Y
yraiv2022-01-25 14:32:54
Unity
yraiv, 2022-01-25 14:32:54

How to attach HPbar to 2d sprite?

Briefly about what I'm trying to do: Enemies will appear in the game and they will be damaged. They will appear the same, I will use a prefab and spawn it every certain time. Faced a problem in the form of attaching a health bar to the character.
Wargs are 2d objects with rb colliders and stuff, they move + turn. The xp bar is a UI element that I redesigned to look like an hpbar.
The question is, how do I attach my UI health bar to an enemy that moves and turns?
I tried it myself and ran into a problem, IMPORTANT, I'll throw it into the prefab later. If the canvas is not a child (then you get 2 prefabs, one canvas, and the second object, well, the enemy), then in order to put links later, I will have to use find by tag and other resource-intensive things, I don’t want to do this. But if I make canvas a child of my enemy, then during the rotation, my xp bar rotates with it, what should I do? (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yraiv, 2022-01-27
@yraiv

I am 100% sure that this is not the best option, but if someone searches, then I did this: I made the object empty (the folder type turned out) in it canvas and the enemy itself. The solution is very simple, although not at all correct, but it works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question