- Home /
Get width of uGUI text object
I am working on a project that uses a canvas with uGUI Text objects. The goal is to have these Text objects instantiated and appended side-by-side, and in order to do that, I am trying to get the width of each actual object.
The main issue is that I am unable to get the actual width of the uGUI Text object; instead, I get the width of the prefab used to instantiate the object. Does anyone know how to access the adjusted/wrapped mesh of each Text object? Otherwise, is there a better solution to this problem?
Answer by DiegoSLTS · Mar 15, 2015 at 02:40 AM
Take a look at the Horizontal Layout Group component, it will place each children one after the other automatically.
If your prefab is a Text it'll work automatically, but if the Text is a child of some other object of the prefab you need to resize the object to fit it's content. Check this link: http://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html
Your answer
Follow this Question
Related Questions
Is It Possible to Render the same Data to 2 Different UI Text Objects? 1 Answer
Text Appears in Inspector but Not on Screen 0 Answers
Canvas UI Priority layers 1 Answer
Get text component uGUI 2 Answers
Unity UI text not appearing on screen. 3 Answers