using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class NPCDialogue : MonoBehaviour { public Text nameText; public Text nameText1; public Text dialogueText; public Dialogue dialogue; public Dialogue dialogueWQuest; public Dialogue dialogueAQuest; private Queue sentences; private Queue sentencesWQuest; private Queue sentencesAQuest; public GameObject Panel; public GameObject QuestPanel; bool triggered = false; public int isQuest; void Start() { sentences = new Queue(); sentencesWQuest = new Queue(); sentencesAQuest = new Queue(); } public void TriggerDialogue() { if (isQuest == 2) { StartDialogue(dialogueWQuest); } else if (isQuest == 3) { StartDialogue(dialogueAQuest); } else { StartDialogue(dialogue); } } void OnTriggerExit2D(Collider2D collision) { if (Panel != null) { Panel.SetActive(false); } triggered = false; } private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { triggered = true; } } void Update() { if (triggered) { if (Input.GetKeyDown(KeyCode.E)) { if (Panel != null) { Panel.SetActive(true); } if (isQuest == 2) { StartDialogue(dialogueWQuest); } else if (isQuest == 2) { StartDialogue(dialogueAQuest); } else { StartDialogue(dialogue); } } } } public void StartDialogue(Dialogue dialogue) { nameText.text = dialogue.name; nameText1.text = dialogue.name; sentences.Clear(); foreach(string sentence in dialogue.sentences) { sentences.Enqueue(sentence); } DisplayNextSentence(); } public void DisplayNextSentence() { if (isQuest == 2) { if (sentences.Count == 0) { EndDialogue(); return; } string sentence = sentences.Dequeue(); dialogueText.text = sentence; } else if (isQuest == 0) { if (sentences.Count == 0) { EndDialogue(); return; } string sentence = sentences.Dequeue(); dialogueText.text = sentence; } else if (isQuest == 4) { if (sentences.Count == 0) { EndDialogue(); return; } string sentence = sentences.Dequeue(); dialogueText.text = sentence; } else if (isQuest == 1) { if (sentences.Count == 0) { QuestPanel.SetActive(true); Panel.SetActive(false); return; } string sentence = sentences.Dequeue(); dialogueText.text = sentence; } } public void EndDialogue() { Panel.SetActive(false); QuestPanel.SetActive(false); } public void QuestAccepted() { isQuest = 2; QuestPanel.SetActive(false); if(!gameObject.GetComponent().IsTaskAccepted()) { Task myTask = gameObject.GetComponent().AcceptTask(); TaskManager.Instance.AddTask(myTask); } else { Debug.Log("Ten task został juz rozpoczęty!"); } } }