]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Dialogue/Dialogue.cs
fd6cde1ce453deb8b7edb77195f64903bb320497
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Dialogue / Dialogue.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5
6 public class Dialogue : MonoBehaviour
7 {
8     public GameObject continueButton;
9     public GameObject dialogueBox;
10     public Text dialogueText;
11     public string[] sentences;
12     private int index;
13     public float typingSpeed;
14
15     void Start()
16     {
17         StartCoroutine(Type());
18     }
19
20     void Update()
21     {
22         if (dialogueText.text == sentences[index])
23         {
24             continueButton.SetActive(true);
25         }
26     }
27
28     IEnumerator Type()
29     {
30         foreach (char letter in sentences[index].ToCharArray())
31         {
32             dialogueText.text += letter;
33             yield return new WaitForSeconds(typingSpeed);
34         }
35     }
36
37     public void NextSentence()
38     {
39         continueButton.SetActive(false);
40
41         if (index < sentences.Length - 1)
42         {
43             index++;
44             dialogueText.text = "";
45             StartCoroutine(Type());
46         }
47         else
48         {
49             dialogueText.text = "";
50             dialogueBox.SetActive(false);
51         }
52     }
53 }