/// <summary> /// Plays the typewriter effect. /// </summary> public override IEnumerator Play() { GUILabel control = GetComponent <GUILabel>(); if (control == null) { yield break; } IsPlaying = true; control.currentLength = 0; while ((control.currentLength + 1) < control.text.Length) { float delay = 1 / charactersPerSecond; if (!DialogueTime.isPaused) { if (audioClip != null && control.currentLength > 0) { control.PlaySound(audioClip); } AdvanceOneCharacter(control); // The code below adds extra delay for punctuation, but I'm not sure I like it: // char c = control.text[control.currentLength]; // if (c == '.' || c == '\n' || c == '!' || c == '?') delay *= 4f; } yield return(StartCoroutine(DialogueTime.WaitForSeconds(delay))); // new WaitForSeconds(delay); } control.currentLength = control.text.Length; control.ResetClosureTags(); IsPlaying = false; }
/// <summary> /// Stops the effect. /// </summary> public override void Stop() { base.Stop(); IsPlaying = false; GUILabel control = GetComponent <GUILabel>(); if (control != null) { control.currentLength = control.text.Length; control.ResetClosureTags(); } }