- Home /
Make UI always center the panel
So I have a panel and it´s child is score. So, score keeps on increasing and once I get over 10 the score text is not centered anymore and if I get over 100 the score text would run off the panel.. How do I make the score text always center the panel? Thank you for all the answers!
Answer by Oliver-Bogdan · Oct 19, 2016 at 02:09 PM
Set the text that contains the score stretch the whole panel. To do this, select the text game object - the one that holds the score - and choose stretch in the dropdown that sits right under Rect Transform (called Anchor Presets). You should choose the horizontal and vertical stretch, the one that is in the bottom-right corner in the dropdown.
In the paragraph section of score text, choose the middle alignment (both vertically and horizontally)
Tick "Best fit" under the paragraph section of the text. <- This is the most important part. Optionally you may choose the Min Size and Max Size for the score text.
Also, make sure you drag the score text's border so that it completely fills the parent panel. (after setting the Stretch Anchor Preset)