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