Question by
yaswong135 · Jun 21, 2019 at 06:27 PM ·
textbeginneruser interfacebutton trigger eventsdialogue
Dialogue not displaying next sentence
I'm somewhat a beginner in Unity trying to create a dialogue box for the start of an e-tutorial in an education app and I can't seem to get the sentences to load.
The first sentence loads after pressing the button, but after that it stops calling the function. It doesn't show the next sentence in the UI or in the Debug.Log.
Is there something I'm missing in the script to stop it from looping??
These are the three scripts I'm using. Based on Brackeys Video: How to Make a Dialogue System in Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour
{
public GameObject Character;
public Text dialogueText;
private Queue<string> sentences;
void Start()
{
sentences = new Queue<string>();
}
public void StartDialogue(Dialogue dialogue)
{
Debug.Log("Starting Conversation");
sentences.Clear();
foreach (string sentence in dialogue.sentences)
{
sentences.Enqueue(sentence);
}
DisplayNextSentence();
}
public void DisplayNextSentence()
{
if (sentences.Count == 0)
{
EndDialogue();
return;
}
string sentence = sentences.Dequeue();
dialogueText.text = sentence;
Debug.Log("Next Sentence");
}
void EndDialogue()
{
Debug.Log("End of Conversation");
Character.gameObject.SetActive(false);
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DialogueTrigger : MonoBehaviour {
public Dialogue dialogue;
public void TriggerDialogue () { FindObjectOfType().StartDialogue(dialogue); } }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue {
public string name;
[TextArea(3,5)]
public string[] sentences;
}
Comment