r/UnityHelp • u/Evening-Conference-5 • Oct 17 '21
PROGRAMMING Question About Sprite Manipulation With Text
Hello Everyone, I am trying to create a gameobject that has a square sprite, the size of the gameobject is depended on 2 factors, one for height and one for width. I've managed to solve the function for height but I still can't manage to produce one for the width. It's function depends on a Text Mesh that is a child of the box. The more the character, the more space. Any idea how i can implement this function?

I have been struggling with problem for quite some time now and i have no clue where to go to solve it.
Thank you very much
3
Upvotes
1
u/Bonejob Code Guru Oct 17 '21
So you want to scale the text based upon the space or the space based upon the text?
Text auto-sizing is designed to scale the text to the defined max point size to fit the text container or RectTransform.
Text Auto-sizing also needs to test various point sizes in order to determine what the optimum point size is for a given text container and as such is not as efficient as just a plain text object with a fixed size.
Given the above, I always recommend users only use Text Auto-sizing to determine the optimum point size for a given text object and then disable this Auto-sizing feature and then manually set the size on all other text objects to this resulting optimum point size. This way you only get the impact of auto-sizing on one object while making sure the point size of all other objects is consistent with the first which does also better UI design / practices.