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