UI Text attach to a specific object?

Hi Kai,

Did you already implement the healthbar? Does it work? If so, you can add Text above it. Maybe you have to create a new element with a Canvas. Set the Canvas to World Space mode.

Use a static text for testing purposes.

Once it works as desired, you could write a StringSetter class or something like that and assign it to the Text game object. Then you can link that StringSetter component to the Enemies component and call a method in the StringSetter instance which updates the text.

A helpful technique: method overloading. If you don’t know what this means, look it up on the internet.

Do everything step by step, and test every step. Then you will very likely be able to solve the problem. Use Debug.Log to verify/falsify assumptions because it is almost impossible to see what’s going on behind the scenes in Unity.

Good luck! :slight_smile:


See also:

1 Like