How to properly yield for an conversation to finish?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Nefisto
Posts: 2
Joined: Tue Aug 13, 2024 12:41 pm

How to properly yield for an conversation to finish?

Post by Nefisto »

Code: Select all

[SerializeField]
private DialogueSystemTrigger dialogTrigger;

protected override IEnumerator MyRoutine ()
{    
    dialogTrigger.OnUse();

    // HERE
    yield return dialogTrigger.WaitForFinish(); //  <<- How to achieve a behavior like this??
    
    // Dialog closed here
}
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to properly yield for an conversation to finish?

Post by Tony Li »

Hi,

Here are two ways:

1. C# events:

Code: Select all

DialogueManager.instance.conversationEnded += OnConversationEnded;
...
void OnConversationEnded(Transform actor)
{
    DialogueManager.instance.conversationEnded += OnConversationEnded;
    Debug.Log("Conversation ended.");
}
2. Or polling:

Code: Select all

while (DialogueManager.isConversationActive) { yield return null; }
Debug.Log("Conversation ended.");
Post Reply