3d, 2d? We need more info
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;
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 at 03:58 PM
Old post but I thought others might get helped by my finding:
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
25 People are following this question.
C# GUI Button
How to create a texture, fill it with some color, add a text at a center and to set this texture to some object in C#?
null texture passed to GUI.DrawTexture
Scrolling typewriter effect
A node in a childnode?