- Home /
How to dynamically add text to the texture of a 3d game object.
I am making a card game. I have a card game object, on which I would like to write the health and damage of the card. These numbers would change throughout the course of the game.
I've done a lot of googling but no one seems to have a way to just add something simple like text to the texture of a game object. (Or it's material or whatever, I'm not picky how it's done).
The closest I've found is that you can create a material and attach a completely transparent texture except for the number, then add that material to the object..and do that for every individual digit. But that seems incredibly wasteful and impractical considering I don't want to stop the numbers after only one or two digits.
Answer by tanoshimi · May 10, 2015 at 07:47 AM
I'm not sure what you've been Googling, but this is the top hit I get when searching for "dynamic Unity text texture", which details at least three ways to achieve this: http://blog.almostlogical.com/2010/08/20/adding-text-to-texture-at-runtime-in-unity3d-without-using-render-texture/
This is old, but still valid. The only difference is that given render textures are now included in all versions of Unity 5, that's probably your best/most flexible option.
I think this will work. $$anonymous$$inda hard to untangle that example code though. Like where is the custom font actually set haha. Thanks!
Your answer
Follow this Question
Related Questions
Make a gameobject with textures semitransparent 3 Answers
Can you assign a material to all Items within an Empty Game Object at once? 1 Answer
Can Someone Help Me With Changing Material / Texture On Collision Event 1 Answer
How to make emissive maps glow? 2 Answers
Can see 3D object through itself 0 Answers