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