Hello! I have a dialog system code with TMPro that works great for all my needs. But when typing, I see tags that are also printed with plain text, and only after typing do I see the style being applied.
How can I make tags work immediately when typing? Thanks!
Here is my script:
void Start()
{
StartCoroutine(PlayDialogue(dialogueSegments[_dialogueIndex]));
}
IEnumerator PlayDialogue(DialogueSegment segment)
{
subjectText.SetText(segment.subjectText);
yield return new WaitForSeconds(0.36f);
_canContinue = false;
_playingDialogue = true;
bodyText.SetText(string.Empty);
float delay = 1f / segment.lettersPerSecond;
for (int i = 0; i < segment.dialogueToPrint.Length; i++)
{
if(_skip)
{
bodyText.SetText(segment.dialogueToPrint);
_skip = false;
break;
}
string chunkToAdd = string.Empty;
chunkToAdd += segment.dialogueToPrint[i];
if (segment.dialogueToPrint[i] == ' ' && i < segment.dialogueToPrint.Length - 1)
{
chunkToAdd = segment.dialogueToPrint.Substring(i, 2);
i++;
}
bodyText.text += chunkToAdd;
yield return new WaitForSeconds(delay);
}
_canContinue = true;
_playingDialogue = false;
_dialogueIndex++;
}