diff options
Diffstat (limited to 'Assets/Scripts/Dialogue')
| -rw-r--r-- | Assets/Scripts/Dialogue/DialogueManager.cs | 47 |
1 files changed, 47 insertions, 0 deletions
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<string> 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);
}
}
|
