I want to call a web service and get some names and have some falling cubes represent each person. I want each side of the cube to have the name printed on it. Can someone point me in the right direction how this is done ? (The easiest way)
No idea if this is the “easiest” way, but you could create a UI with text labels spaced evenly in a grid pattern. So if you knew the max number of names was 16, you could create a 4 x 4 grid of labels. Then you could have 16 unique cube meshes with their UV coordinates set to each include the area of one of the 16 cells. Those cubes could either be procedurally generated for more flexibility or manually created in a modeling package.
Then you’d have the camera that’s rendering the UI set up to output to a render texture. Each cube would be set to a material that used that render texture. You could have 16 prefabs for the cubes and instantiate whichever ones you need. Set the text labels to your names.
Since each cube would share the same texture, I think they would batch into a single draw call for the cubes.
So I would dynamically create a 2D bitmap that I programmatically write the name to? And then assigned that as a texture to a cube… And then loop that creating a new bitmap + cube for each name ?
Dynamically creating a 2D bitmap is something Unity can do for you. It’s called a render texture. Anything that a camera sees can be output to a render texture “live”. That includes cameras that are seeing just a UI canvas.
What I’m picturing is having a single render texture that contains all of your names, spaced out evenly. You’d have one single material that uses that one texture.
So it wouldn’t require a separate texture for each cube, but each cube would points to its “cell” within the single texture by having very specific UV coordinates. Each cube would have unique UV coordinates set to just its portion of the texture. You could have each of the six faces use that same area so that the name was on each face of the cube. You wouldn’t be able to use a standard cube for that. You’d have to either author cubes manually in Blender or something or create them procedurally in Unity (which could be less labor intensive and more flexible).
Anyway, to set the names, you’d set the appropriate “Text” UI objects in your UI canvas to the names.
Sounds a little like this question I answered Adding text to dynamically spawned cubes - Questions & Answers - Unity Discussions