2 using System.Collections;
3 using System.Collections.Generic;
7 public class Dialogue : MonoBehaviour
9 public GameObject continueButton;
10 public GameObject dialogueBox;
11 public GameObject SpeechBubble;
12 public GameObject mouse;
14 SpeechBubble speechBubble;
16 public Text dialogueText;
18 public string[] sentences;
23 public float typingSpeed;
29 dialogueBox.SetActive(false);
30 continueButton.SetActive(false);
31 SpeechBubble.SetActive(false);
32 speechBubble = SpeechBubble.GetComponent<SpeechBubble>();
37 if (dialogueText.text == sentences[index])
39 continueButton.SetActive(true);
42 if (dialogueText.text != sentences[index])
44 if (Input.GetKeyDown(KeyCode.Return) || Input.GetMouseButtonDown(0))
54 public IEnumerator Type()
56 dialogueBox.SetActive(true);
57 speechBubble.NextSpeaker();
58 SpeechBubble.SetActive(true);
59 foreach (char letter in sentences[index].ToCharArray())
61 dialogueText.text += letter;
62 yield return new WaitForSeconds(typingSpeed);
68 dialogueText.text = sentences[index];
71 public void NextSentence()
73 FindObjectOfType<AudioManager>().Play("click");
74 continueButton.SetActive(false);
77 if (index < sentences.Length - 1)
80 dialogueText.text = "";
81 StartCoroutine(Type());
82 speechBubble.NextSpeaker();
86 dialogueText.text = "";
87 dialogueBox.SetActive(false);
88 SpeechBubble.SetActive(false);
89 mouse.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
90 mouse.GetComponent<MouseController>().enabled = true;