Hey there, I have a strange problem with my code.
As you can see below this code should display a certain text with a typewriter effect.
First text01 should be printed (text is assigned in unity interface) and after 10.5 seconds the text should get removed and text02 should be printed.
However the WaitForSeconds doesn’t seem to work.
While text01 gets printed, text02 gehts printed too … this is also true for text03 …
Whats the matter?
Hope you can help me
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TypeWriterEffect : MonoBehaviour {
public float delay = 0.1F;
public string text01;
public string text02;
public string text03;
private string currentText = "";
// Use this for initialization
void Start () {
StartCoroutine(writeText(text01));
clearText();
StartCoroutine(writeText(text02));
clearText();
StartCoroutine(writeText(text03));
}
void clearText()
{
this.GetComponent<Text>().text = "";
}
IEnumerator writeText(string text){
for (int i = 0; i < text.Length; i++)
{
currentText = text.Substring(0, i + 1);
this.GetComponent<Text>().text = currentText;
yield return new WaitForSeconds(delay);
}
yield return new WaitForSeconds(10.5F);
}
}