- Home /
How to display text on a cube and how to change it dynamically?
2D, but I'm using 3D figures. I want to fill this cube with some color and to add a text at a center.. how to do that?
Answer by Owen-Reynolds · May 07, 2014 at 03:27 PM
Paste (child) a 3DText over it. Change it the usual way for 3DText (also called TextMeshes.)
The other way, changing the cube texture itself, would be a huge pain. Have to fix the unwrap (the Unity cube assigns entire texture to each face,) and so on.
Hah, changing the cube texture IS what I'm after, probably.. and there's no need to fix the unwrap, it's fine.
I've been thinking about smthg like this:
Texture2D texture = null;
Color fillColor = new Color (1, 0.0f, 0.0f);
Color[] fillColorArray = texture.GetPixels ();
for (int m=0; i<fillColorArray.Length; ++m)
{
fillColorArray[i] = fillColor;
}
texture.SetPixels (fillColorArray);
texture.Apply ();
material.mainTexture = texture;
GameObject.Find("object_name").transform.renderer.material = material;
but how to put a text into that texture? And how to do all this from a code?
Well, like I said, I think putting it directly on the texture would be a huge pain. There's no easy way to access a letter texture, much less a whole word; or put it on only 1 side; or scale/rotate/position the word pixels onto the mainTexture pixels.
If you have a few fixed phrases, most people would just pre-make textures with those, get them all nice, and swap textures (or even materials) in-game.
Older material, but it should still work:
Answer by i1drago · Apr 19, 2017 at 03:58 PM
Old post but I thought others might get helped by my finding:
http://geek1337.blogspot.se/2017/04/unity3d-creating-cube-with-text-on-each.html
Your answer
Follow this Question
Related Questions
C# GUI Button 2 Answers
A node in a childnode? 1 Answer
C# cannot convert 'char' expression to type 'UnityEngine.Texture' 1 Answer
GUI text disapearing randomly. 0 Answers