Page 1 of 1
Run Code on Conversation Escape
Posted: Sat Aug 05, 2023 1:24 pm
by Kerple
I'm using a dialogue system to access a computer UI. On activation of the conversation the computer turns on and displays the UI. However, if the player hits escape the rest of the conversation that resets the computer and turns it off doesn't run.
So I'm looking to run code if the player leaves this particular conversation early by hitting escape.
Re: Run Code on Conversation Escape
Posted: Sat Aug 05, 2023 2:42 pm
by Tony Li
Hi,
In code, you can hook into
DialogueManager.instance.conversationEnded:
Code: Select all
DialogueManager.instance.conversationEnded += OnConversationEnded;
DialogueManager.StartConversation("title");
...
void OnConversationEnded(Transform actor)
{
DialogueManager.instance.conversationEnded -= OnConversationEnded;
if (DialogueManager.lastConversationEnded == "title")
{
// (do your stuff here)
}
}
Or add an
OnConversationEnd() method to a script that's on the Dialogue Manager or the computer:
Code: Select all
void OnConversationEnd(Transform actor)
{
if (DialogueManager.lastConversationEnded == "title")
{
// (do your stuff here)
}
}
If you put it on the computer GameObject, it will only be called if the computer GameObject is the conversation actor or conversation conversant. If you put it on the Dialogue Manager, it will be called for every conversation.
Or add a
Dialogue System Events component to the computer GameObject and configure the OnConversationEnd() UnityEvent.
If you only want to run code if the player pressed the Dialogue Manager's Input Settings > Cancel Conversation Input, use an OnConversationCancelled() method instead.
Re: Run Code on Conversation Escape
Posted: Sat Aug 05, 2023 8:33 pm
by Kerple
I was able to fix it with your help thank you very much!
Re: Run Code on Conversation Escape
Posted: Sat Aug 05, 2023 9:17 pm
by Tony Li
Glad to help!