I have some Text objects in UI. And I set Best Fit to true for all of them.the problem that I face,is that the length of their texts are variable,therefore their responsive font sizes are different from each other.
I tried to write this script to change the font size of all texts to the smallest one but it wont work. How can I overcome this problem?
public class FontResizer : MonoBehaviour {
public Text[] txtBoxes;
public float[] fontSizes;
float min;
void Start () {
fontSizes = new float[txtBoxes.Length];
for (int i = 0; i < fontSizes.Length; i++)
{
fontSizes _= txtBoxes*.cachedTextGenerator.fontSizeUsedForBestFit;*_
}
min = 100000;
for (int i = 0; i < fontSizes.Length; i++)
{
if (min > fontSizes*)*
{
min = fontSizes*;*
}
}
for (int i = 0; i < fontSizes.Length; i++)
{
txtBoxes*.resizeTextForBestFit = false;*
}
for (int i = 0; i < fontSizes.Length; i++)
{
txtBoxes*.fontSize = Mathf.FloorToInt(min);*
}
}
}