bool alreadyClicked = false;
private string message;
IEnumerator TypeText () {
foreach (char letter in message.ToCharArray()) {
guiText.text += letter;
if (Singleton.Instance)
Singleton.Instance.audio.PlayOneShot (sound);
yield return 0;
yield return new WaitForSeconds (letterPause);
}
}
IEnumerator Timer (float timeOut) {
yield return new WaitForSeconds (timeOut);
ChangeMenuActivity (true);
showUI = true;
enabled = false;
guiText.text = "";
//Destroy (this); //destroys the script
}
void ChangeText(string text)
{
guiText.text = text;
if (!alreadyClicked) {
alreadyClicked = true;
StopCoroutine("TypeText");
message = text;
guiText.text = "";
StartCoroutine("TypeText");
}
float temp = message.Length * letterPause + 1;
StartCoroutine(Timer(temp));
}
The only problem i'm having is for some reason the text merges together after clicking. The guiText.text += letter doesn't clear when it clearly should because of this
StopCoroutine("TypeText");
message = text;
guiText.text = "";
what am i missing?
↧