Question by
AmazingDeveloper2 · Mar 30, 2016 at 03:29 PM ·
unity 5uitextcanvas
How can I check if there is no free space in the Text component?
In my canvas component I print text one symbol after another and I need to stop printing if text does not fit. After press next button other part of the text will be printed. But how can I check if there is no free space in the Text component? I don't need slider here. If all symbols are "i", then I can print 432 of it. And if "w" - then 126.
private IEnumerator TextDelay()
{
isTextTyping = true;
foreach (char i in
contentToPrint.stringsToPrint[NumberOfStringToPrint])
{
if (i != ' ')
audioTapText.Play();
textComponent.text += i;
yield return new WaitForSeconds(0.04f);
}
isTextTyping = false;
}
And I don't want to print half of the word at the end. Then, after press next, print other half
1.jpg
(137.3 kB)
Comment
Best Answer
Answer by pfreese · Apr 01, 2016 at 06:09 PM
By querying the TextGenerator (http://docs.unity3d.com/ScriptReference/TextGenerator.html) on the Text component, you can find out how many characters are visible. When this stops increasing, you know you've hit your limit on visible characters.