Coroutines: Dynamic Text
Coroutines
//this allows single characters to be added to look like typed text
IEnumerator TypeSentence(string sentence)
{
dialogText.text = ""; //clear previous sentance
foreach (char letter in sentence.ToCharArray())
{
dialogText.text += letter;
yield return new WaitForSeconds(0.05f); //execution pauses here
}
}/
//Example Use: in GetNextDialog( ) method
StopAllCoroutines(); //stop if still running from prior dialog
string curSentence = item.dialogText;
StartCoroutine( TypeSentence( curSentence ) );Last updated