Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- public class DialogueManager : MonoBehaviour
- {
- int Count = 0;
- public GameObject DialogueBox;
- public GameObject textBoxObj;
- public GameObject talkerTextBox;
- AudioSource SFX;
- private void Start()
- {
- SFX = this.GetComponent<AudioSource>();
- }
- public void StartDialogue(int count, string[] lines, string talker)
- {
- Count = count;
- DialogueBox.SetActive(true);
- talkerTextBox.GetComponent<TextMeshProUGUI>().text = talker;
- ChangeText(lines);
- }
- public void ChangeText(string[] lines)
- {
- if (Count >= lines.Length)
- {
- DialogueBox.SetActive(false);
- return;
- }
- textBoxObj.GetComponent<TextMeshProUGUI>().text = lines[Count];
- SFX.Play();
- StartCoroutine(WaitForKeyPress(lines));
- }
- private IEnumerator WaitForKeyPress(string[] lines)
- {
- bool done = false;
- while (!done)
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- done = true;
- }
- yield return null;
- }
- Count++;
- ChangeText(lines);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment