Reputation: 159
I'm using Unity3D with C#. Well, I have a dialogue text script with a foreach that run the sentences list, I need to know how I can know when the first sentence finishes.
Here is my code :
public void StartDialogue(Dialogue dialogue)
{
//Debug.Log("Start conversation with " + dialogue.name);
cameradialogue.SetActive(true);
FindObjectOfType<ThirdPersonCharacter> ().isStop = true;
DialogueBox.SetActive (true);
NameText.text = dialogue.name;
sentences.Clear();
foreach (string sentence in dialogue.sentences)
sentences.Enqueue (sentence);
DisplayNextSentence();
}
Here my method for display my setences:
IEnumerator TypeSentence (string sentence){
dialogueText.text = "";
foreach (char letter in sentence.ToCharArray()) {
dialogueText.text += letter;
yield return null;
}
}
Upvotes: 0
Views: 379
Reputation: 118
When the foreach loop will finish in the TypeSentence method, It will mean that the complete sentence has been displayed in the dialog text.
Upvotes: 1