Hi Tony
I want to setup a variable to change on "Start" and "End" of every conversation. I found events:
- OnConversationStart()
- OnConversationEnd()
can I setup my variable by monitoring those events?
Also if i use method "DialogueManager.StopConversation()", OnConversationEnd() would be propagated or not?
Also is there another method to check for end and start of conversation?
How to check for Start and End of conversation via code
-
- Posts: 15
- Joined: Thu Dec 16, 2021 2:09 pm
Re: How to check for Start and End of conversation via code
I believe this is what you're looking for:
Hope that helps!
PS: Remember to unsubscribe (-=) to the events in OnDestroy or whatever, depending on how your code works!
Code: Select all
DialogueManager.instance.conversationStarted += MyConversationStarted;
DialogueManager.instance.conversationEnded += MyConversationEnded;
// make your own functions like this:
private void MyConversationEnded(Transform t){}
PS: Remember to unsubscribe (-=) to the events in OnDestroy or whatever, depending on how your code works!
Code: Select all
DialogueManager.instance.conversationStarted -= MyConversationStarted;
Re: How to check for Start and End of conversation via code
I was thinking about somthing like this:
Code: Select all
public class DialogueConversationMonitor : InjectableMonoBehaviour
{
public override void DependenciesResolved()
{
EventSystem.Receive<OnConversationStart>().Subscribe(x => ChangeConversationStateToTrue()).AddTo(this);
EventSystem.Receive<OnConversationEnd>().Subscribe(x => ChangeConversationStateToFalse()).AddTo(this);
}
private void Update()
{
}
private void ChangeConversationStateToTrue()
{
DialogueLua.SetVariable("InConversation", true);
}
private void ChangeConversationStateToFalse()
{
DialogueLua.SetVariable("InConversation", false);
}
}
Re: How to check for Start and End of conversation via code
Hi,
No need for that. I recommend DarkProphet's method above.
No need for that. I recommend DarkProphet's method above.