Ui over object

Hello! I want to display a number over my 3d Unity object. Could you help me?
I already tried this:

Void Update() {
       text.transform.position = Camera.main.WorldToScreenPoint(this.transform.position)


}

But it looked weird. It didn’t follow the object after it got close to the side of the screen.

In the method in which the canvas is attached to the game object as a child, I couldn’t resize the text to be enough small but also be readable.

I would be grateful for any help. :slight_smile:

It appears you are already doing it fundamentally correctly.

As far as controlling the size of the text, this is usually done either by a content size fitter control, or by manually limiting how large or small it can get. Or you can specifically leave it at a particular font size that works for all distances/positions. You can also hide the text part when it gets too far away or too close.

Without knowing more about your context (is it a 3D world canvas? Is it floating over the screen as 2D? etc.) it’s hard to say much more.

1 Like

Thanks for the answer!
I am working on a 3D simulation where the text should display statistics about the character.

If you want just one number or a little more text, you may use TextMesh embedded into 3d character. It will just move with it as any other objects in hierarchy do and that’s it.

Like Kurt said…put the canvas in world space then you can attach it with a smooth follow or whatever.