I'm making a 2d board-game-style game in Unity 5, and I have a prefab made up of a couple of sprites which represents a game piece. I want some text in my prefab that I can update as the game progresses.
If i try to add text, it requires a canvas, but when I create a canvas, an extraordinarily enormous canvas is created, that looks to be at least 1000x times bigger than by camera area. If I try to place this canvas inside my prefab, my prefab is now made of an enormously huge canvas, and my tiny sprite images. This makes the prefab impossible to position, or calculate sizing or animate, or anything else I want to do.
How can I add text to a prefab, and make the text contained within the size of my prefab spites?
Here's what I have tried so far:
if I set the canvas for the text to "Render Mode: World Space" I'm able to make it's rect tranform smaller. However, if I get it as small as my sprites, the text becomes an unreadably blurry mess. I guess this happens because my sprites are literally at least 1000x smaller than the canvas, so when I zoom in enough to even see the sprites, the text has been zoomed into oblivion. My sprites are so much smaller than the canvas, that if I am zoomed out to see the full canvas, my sprites are not even visible.
I'm able to kind of make things work if I recreate my prefab using UI Images instead of sprites. This way, the UI Images, and the text are both UI elements contained in the enormous canvas, so the size disparity doesn't exist. However, I don't know what the pitfalls are going to be trying to build an entire game out of ui images instead of sprites. Do I get all the state capabilities of sprites?
The canvas Unity generates that is 1000x bigger is used for GUI related objects that are not meant to directly interact with the game world like the score or buttons. In order to have moving text, try using 3DText. Have the text face the camera so that the text appears to be 2D. You can find this option in the menu under
GameObject => 3D Object => 3D Text.
From what I understand, all you need to do is parent this GameObject to your prefab and do some script magic at runtime.
For high fidelity text, either decrease the character size or increase the font size or do both.
Note: A larger character size reduces fidelity, but will take less processing power.
Source: Unity 5.2.0f3