Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- public class DialogueWindow : MonoBehaviour
- {
- public const float kMaxTextTime = 0.1f;
- public static int TextSpeed = 2;
- public TMP_Text Text;
- public string CurrentText;
- protected enum TextStateType
- {
- None,
- Writing,
- Waiting
- }
- TextStateType TextState;
- CanvasGroup Group;
- private void Start()
- {
- Group = GetComponent<CanvasGroup>();
- Group.alpha = 0;
- }
- public void Show(string dialogue)
- {
- CurrentText = dialogue;
- StartCoroutine(DisplayText());
- Group.alpha = 1;
- }
- public void Close()
- {
- Group.alpha = 0;
- Text.text = "";
- TextState = TextStateType.None;
- }
- protected IEnumerator DisplayText()
- {
- Text.text = "";
- TextState = TextStateType.Writing;
- foreach (char c in CurrentText.ToCharArray())
- {
- Text.text += c;
- yield return new WaitForSecondsRealtime(kMaxTextTime / TextSpeed);
- }
- TextState = TextStateType.Waiting;
- yield return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment