]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Dialogue/Dialogue.cs
dialogue-system v0.9
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Dialogue / Dialogue.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using UnityEngine;
5 using UnityEngine.UI;
6
7 public class Dialogue : MonoBehaviour
8 {
9     public GameObject continueButton;
10     public GameObject skipButton;
11     public GameObject dialogueBox;
12     public GameObject SpeechBubble;
13     public GameObject mouse;
14
15     SpeechBubble speechBubble;
16
17     public Text dialogueText;
18
19     [HideInInspector] public int index;
20
21     public float typingSpeed;
22
23     [SerializeField] DialogueTrigger[] dialogueTriggerer;
24
25     void Start()
26     {
27         dialogueBox.SetActive(false);
28         continueButton.SetActive(false);
29         skipButton.SetActive(false);
30         SpeechBubble.SetActive(false);
31         speechBubble = SpeechBubble.GetComponent<SpeechBubble>();
32     }
33
34     void Update()
35     {
36         if (dialogueText.text == dialogueTriggerer[0].stringFromFile[0].text)
37         {
38             continueButton.SetActive(true);
39             skipButton.SetActive(true);
40         }
41     }
42
43     public IEnumerator Type()
44     {
45         dialogueBox.SetActive(true);
46         skipButton.SetActive(true);
47         speechBubble.NextSpeaker();
48         SpeechBubble.SetActive(true);
49         /*foreach (char letter in sentences[index].ToCharArray())
50         {
51             dialogueText.text += letter;
52             yield return new WaitForSeconds(typingSpeed);
53         }*/
54
55         //dialogueText.text = dialogueTrigger.stringFromFile[0].text;
56
57         foreach (char letter in dialogueTriggerer[0].stringFromFile[1].text.ToCharArray())
58         {
59             dialogueText.text += letter;
60             yield return new WaitForSeconds(typingSpeed);
61         }
62     }
63
64     public void NextSentence()
65     {
66         /*FindObjectOfType<AudioManager>().Play("click");
67         continueButton.SetActive(false);
68
69         if (index < sentences.Length - 1)
70         {
71             index++;
72             dialogueText.text = "";
73             StartCoroutine(Type());
74             speechBubble.NextSpeaker();
75         }
76         else
77         {
78             dialogueText.text = "";
79             dialogueBox.SetActive(false);
80             SpeechBubble.SetActive(false);
81             mouse.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
82             mouse.GetComponent<MouseController>().enabled = true;
83         }*/
84         dialogueText.text = dialogueTriggerer[0].stringFromFile[0].text;
85     }
86
87     public void Skip()
88     {
89         /*StopCoroutine(Type());
90         FindObjectOfType<AudioManager>().Play("click");
91         skipButton.SetActive(false);
92
93         if (index < sentences.Length - 1)
94         {
95             index++;
96             dialogueText.text = "";
97             dialogueText.text = sentences[index];
98             speechBubble.NextSpeaker();
99         }
100         else
101         {
102             dialogueText.text = "";
103             dialogueBox.SetActive(false);
104             SpeechBubble.SetActive(false);
105             mouse.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
106             mouse.GetComponent<MouseController>().enabled = true;
107         }*/
108         dialogueText.text = dialogueTriggerer[0].stringFromFile[0].text;
109     }
110 }