Move a Text attached to a sprite

Hello all !

I am currently struggling to get a text field to move with a sprite (an image as background).

What I did is add my image as a sprite in my hierarchy. I assigned my script to get it moving around (it works).
Now it is blank and I want to add text hover that I can change programmatically. So I added a text as a child to the sprite to move it with the sprite but it wasn’t moving. So I applied the same moving script to the child text but it does move quite the same way. It seems to be moving inside the sprite or canvas I don’t know.

I don’t know if I am clear but I just want to move an image with a text hover which I can change programmatically in a script.

Do you know how I can do this ? ^^

Thanks !

Hey.

You have 2 options. You could continue to use the UI text component and use this inside a canvas that you make a child object of your sprite. Once you’ve made the canvas a child of your game object. You would need to go to the canvas inspector and change it from screen space - overlay to world space. You just need to then adjust the size of the canvas and text accordingly.

Other option would be to add a text and mesh renderer. You just need to set your font and use this like any other game object.

Hope this helps

Thanks a lot for you answer! I am going to try both to see how it goes.
Maybe there is a best practice to do it ? :slight_smile: