I want to run some code every time the speaker in a conversation changes. Where / how do I do this?
I want this to apply to all conversations throughout the game.
Also, I need who is speaking (gameObject or name text) as an argument.
Event That Is Called Every Time The Speaker Changes
Re: Event That Is Called Every Time The Speaker Changes
Hi,
Add a script with an OnConversationLine method to the Dialogue Manager. Example:
Add a script with an OnConversationLine method to the Dialogue Manager. Example:
Code: Select all
using UnityEngine;
using UnityEngine.Events;
using PixelCrushers.DialogueSystem;
public class EventEveryTimeSpeakerChanges : MonoBehaviour
{
public UnityEvent onSpeakerChange;
private Transform lastSpeaker;
void OnConversationStart(Transform actor) { lastSpeaker = null; }
void OnConversationLine(Subtitle subtitle)
{
if (!string.IsNullOrEmpty(subtitle.formattedText.text) && subtitle.speakerInfo.transform != lastSpeaker)
{
lastSpeaker = subtitle.speakerInfo.transform;
onSpeakerChange.Invoke();
}
}
}