Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach text to a gameobject [closed]

I know there are 2 ways to do it. But none of them works for me.

The first way I tried is to create a gameObject and then put a cube(shape) and a canvas with Text in it. I set the position of shape, canvas(world space) and text to (0,0,0) so that they will stay together. However, Only the cube showed up. And disabling the cube still doesn't make the text display.

enter image description here

Shape

So I removed it and added Text Mesh to the shape and this required me to remove Mesh Filter. And now what I can see is only an empty space. Do I have any settings wrong?

enter image description here

like image 905
Seaky Lone Avatar asked Nov 05 '25 01:11

Seaky Lone


1 Answers

You can do that with a UI Button game object and a 3D cube. The steps are as follows:

  1. In your empty scene, create a 3D Cube.

  2. After that, create a UI Button object.

  3. Now that you have the button and the Canvas, drag the Canvas to become a child of the cube, like this:

    enter image description here

  4. Now you have to set the Canvas to World Space render mode, remove the Canvas Scaler component, and set Width = Height = 1 and all Pos = 0.

  5. Final step, setup the Button: set Width = Height = 100, all Scale = 0.01 and Pos Z = -0.501.

Now you have a perfectly functional button that will stay attached to the front face of the cube, no matter where the cube is positioned or rotated.

You can of course add as many buttons you want, and position them to different faces of the cube (even more than one button to a single face etc.).

enter image description here

like image 59
Galandil Avatar answered Nov 07 '25 15:11

Galandil