- Home /
Changing text on Canvas Text is very slow / unresponsive
Hi,
I'm trying to animate a text on a Canvas/Text with the following snippet:
foreach (char letter in message.ToCharArray()) {
txtCanvas.text += letter;
yield return new WaitForSeconds (letterPause);
//Debug.Log(Time.time);
}
It works but it is incredibly slow... I cannot even get 5 characters drawn per second. Even when the game runs at 100 FPS in the editor, the characters on the string won't be animating smoothly.
Any hint or clue what I'm doing wrong ?
Have you tried using Text$$anonymous$$eshPro (now free with Unity) ins$$anonymous$$d of Unity UI's Text component?
Answer by MechaWolf99 · Apr 17, 2018 at 01:55 PM
My guess would be yield return new WaitForSeconds (letterPause);
. But I don't know what letterPause
is set to. What is it set to?
Thanks $$anonymous$$echaWolf! $$anonymous$$y bad forgot to mention- but no. For any letterPause it won't work smoothly. With letter pause of 0.033 it should draw 33 characters per second but it does maybe 4-5.... with 0.1 it does maybe 2-3.
Okay, so I did a quick google search for you and found this other question.
Then did a very small modification to it to make it work for text canvas. Hope this helps :)
private Text text;
// Use this for initialization
void Start () {
text = GetComponent<Text>();
StartCoroutine(AnimateText(text.text));
}
IEnumerator AnimateText(string strComplete)
{
int i = 0;
text.text = "";
while (i < strComplete.Length)
{
text.text += strComplete[i++];
yield return new WaitForSeconds(0.03F);
}
}
This is just a different way of writing the for loop... Unfortunately doesn't help
Did you try that code? Like, only that code in it's own script, on the same gameObject as the text element? Because I tried it before posting and it worked perfectly.
Your answer
Follow this Question
Related Questions
yield WaitForSeconds compatibility? 0 Answers
WaitForSeconds does not work 1 Answer
How do i position this text to go where i want? 1 Answer