- Home /
One Dialogue running before another
I am working on one of my first 3D games, and i recently made a dialogue system. There is four parts, a few lines of code to call the trigger, the trigger, and a dialog script that attaches inside of the dialogue trigger where I can write the text that gets queued. As well as the dialogue manager. The dialogue script that goes inside of trigger script in the inspector look like this:
[System.Serializable] public class Dialog { public string name;
[TextArea(2, 10)]
public string[] scentences;
}
FindObjectOfType().TriggerDialoug();
Secondly, the trigger script looks like this:
public class DialogTrigger : MonoBehaviour
public Dialog dialog;
public void TriggerDialoug()
{
FindObjectOfType<DialougManager>().StartDialouge(dialog);
}
That script than calls this script here:
public class DialougManager : MonoBehaviour
public Queue<string> scentences;
public Text nameText;
public Text dialogText;
public Animator animator;
// Start is called before the first frame update
void Start()
{
scentences = new Queue<string>();
}
public void StartDialouge(Dialog dialog)
{
animator.SetBool("IsOpen", true);
nameText.text = dialog.name;
scentences.Clear();
foreach (string scentence in dialog.scentences)
{
scentences.Enqueue(scentence);
}
DisplayNextSentence();
}
public void DisplayNextSentence()
{
if(scentences.Count == 0)
{
EndDialouge();
return;
}
string scentence = scentences.Dequeue();
StopAllCoroutines();
StartCoroutine(TypeScentence(scentence));
}
IEnumerator TypeScentence (string sentence)
{
dialogText.text = "";
foreach (char letter in sentence.ToCharArray())
{
dialogText.text += letter;
yield return null;
}
}
public void EndDialouge()
{
animator.SetBool("IsOpen", false);
}
}
This script basically just takes the queue and puts it into text on the screen in order.
I have three different sections of dialogue set up right now, one at the start of the game, which works great. And one after you open a chest, which also works if I don't have the third section of dialogue setup. As soon as i put in the third one, the second one stops working. I have checked to make sure its not a problem with the scripts that call the trigger, so I have determined that its a problem with the queue, but I have no way to see the queue because it isn't visible in the inspector. Sorry if this is messy, I have never posted on here before, and don't really know how to get my point across. Thanks in advance :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Binary Heap Minimum value 1 Answer