UI Text attach to a specific object?

An example of what I mean is that The Number Of Level attach to the Enemies: wherever the enemy go, the text comes along. But The canvas for displaying the text would follow the camera. The “Level” would comes up after certain amount of time. So the text need to be updated. Moreover, different types of enemies has different amount of time to level up. Thus, I cannot display it the Text as a sprite. How to make this? Any link to the instruction videos? And what this approach call?

P/s: I have only learned Unity and coding for less than 2 months with the 2D course of GaveDev.tv in Udemy. So a lot of technical words for coding or about Unity, I do not really know much.

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

Thanks NIna,
I would try my best!
Beside, I have completed the 2d Complete Course Unity, what course would you suggest for me? Come to the RPG course or learn the 3d Course first?

It works. Thanks!

1 Like

Good job! I knew you would be able to solve the problem. :slight_smile:


Regarding your questions on the next course, how familiar do you feel with Unity and programming? The 3D course covers the fundamentals of programming, just like the 2D course. Since you appear to be able to solve problems, I tend to recommend the more advanced RPG course.

The reasons for my suggestion are:

  1. Rick is currently remastering the 3D course, and it might take a while until he uploads the new videos.
  2. You completed the 2D course, so you have some experience.
  3. You successfully realised one of your own ideas yourself.
  4. If you feel that you are lacking knowledge, you could take a break from the RPG course and follow the 3D course instead.

This is just my opinion. Do what you feel is best for you. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms