]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Dialogue/Dialogue.cs
38cbb4d30fe8672414830d3a39ee7797b5f14e15
[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 GameObject SpeechBubble;
11     public GameObject mouse;
12
13     SpeechBubble speechBubble;
14
15     public Text dialogueText;
16
17     public string[] sentences;
18     public int index;
19
20     public float typingSpeed;
21
22     void Start()
23     {
24         dialogueBox.SetActive(false);
25         continueButton.SetActive(false);
26         SpeechBubble.SetActive(false);
27         speechBubble = SpeechBubble.GetComponent<SpeechBubble>(); 
28     }
29
30     void Update()
31     {
32         if (dialogueText.text == sentences[index])
33         {
34             continueButton.SetActive(true);
35         }
36     }
37
38     public IEnumerator Type()
39     {
40         dialogueBox.SetActive(true);
41         speechBubble.NextSpeaker();
42         SpeechBubble.SetActive(true);
43         foreach (char letter in sentences[index].ToCharArray())
44         {
45             dialogueText.text += letter;
46             yield return new WaitForSeconds(typingSpeed);
47         }
48     }
49
50     public void NextSentence()
51     {
52         continueButton.SetActive(false);
53
54         if (index < sentences.Length - 1)
55         {
56             index++;
57             dialogueText.text = "";
58             StartCoroutine(Type());
59             speechBubble.NextSpeaker();
60         }
61         else
62         {
63             dialogueText.text = "";
64             dialogueBox.SetActive(false);
65             SpeechBubble.SetActive(false);
66             mouse.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
67         }
68     }
69 }