I have some text. And i want to use some graphics in the text. So i made some sprites, and have placed them at their position in text.
This works fine for my native resolution. But when i change the resolution then the text changes its size, and the distance between the letters and the lines too. And so the sprites does not fit to the text anymore.
How can i fix this?
First image is my native resolution 1024x768. Second image is 754x563, captured in the Editor. As you can see, the sprites are still at their original positions, but the text itself is different distributed, caused by the different distance between the letters and the lines. And covers now the sprites.
Since the sprites are not part of the text, their position isn’t relative to any given character. So as the resolution changes this affects the position of the characters, lines also due to word wrapping, so the sprites simply get out of alignment.
One way would be for you to add the sprites into your font by creating a custom bitmap font but that would also require not using a dynamic font which you sort of want to handle the different resolutions. With the sprites added into the custom bitmap font, they are essentially treated the same as characters and thus move / wrap as expected.
Alternatively, you could look into TextMesh Pro which is a replacement for Unity’s UI.Text Component which among other things supports the ability to add sprites inline with text using the tag. Here is an example of this from the following post / thread.
The little numbers indicate the draw calls. In this example, you have 3 text objects using 2 Font Assets and 2 different Sprite Assets or 4 different materials and thus a total of 4 draws calls. Like any other materials in Unity, they benefit from dynamic batching.
Here is a video which explains this tag feature in details.
Note: The latest releases of TextMesh Pro which include additional features and support for the New UI & Unity 5.0 are available to all registered users of the product on the TextMesh Pro User Forum.
I still wonder why the text is changing the character and line distance in the text at all with scaling the game. But it seems that i have to live with that behaviour then
Yes i know. But it doesn’t make a big difference to the problem if i use Best fit or not. The text changes its appearing in both cases when i scale the screen.
I have for now simply fixed it by dividing the whole text into several paragraphs, means more text components. So that at least the paragraphs stays at their positions. I don’t have this much text to display, so i can get away with that solution
Found a workaround. In Rendermode World space the text does not jump around. This has of course the drawback that the UI is now in worldspace, and may need its own UI camera now …