From d1c6d296e85646853f7aaa5a07e6d5718fce0072 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 24 Aug 2020 17:18:52 -0400 Subject: Pause menu; Dialogue; New font --- Assets/Scripts/Dialogue/DialogueManager.cs | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'Assets/Scripts/Dialogue/DialogueManager.cs') diff --git a/Assets/Scripts/Dialogue/DialogueManager.cs b/Assets/Scripts/Dialogue/DialogueManager.cs index 056e7d9..4a7b540 100644 --- a/Assets/Scripts/Dialogue/DialogueManager.cs +++ b/Assets/Scripts/Dialogue/DialogueManager.cs @@ -1,9 +1,14 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class DialogueManager : MonoBehaviour { + public Text nameText; + public Text dialogueText; + + public Animator animator; private Queue sentences; @@ -15,7 +20,49 @@ public class DialogueManager : MonoBehaviour public void StartDialogue(Dialogue dialogue) { + animator.SetBool("IsOpen", true); + Debug.Log("Starting conversation with " + dialogue.name); + + nameText.text = dialogue.name; + + sentences.Clear(); + + foreach (string sentence in dialogue.sentences) + { + sentences.Enqueue(sentence); + } + + DisplayNextSentences(); + } + + public void DisplayNextSentences() + { + if (sentences.Count == 0) + { + EndDialogue(); + return; + } + + string sentence = sentences.Dequeue(); + StopAllCoroutines(); + StartCoroutine(TypeSentence(sentence)); + } + + IEnumerator TypeSentence(string sentence) + { + dialogueText.text = ""; + foreach (char letter in sentence.ToCharArray()) + { + dialogueText.text += letter; + yield return null; + } + } + + void EndDialogue() + { + Debug.Log("End of conversation."); + animator.SetBool("IsOpen", false); } } -- cgit v1.2.3