Page 1 of 1

[Solved] How to grab the current speaker name

Posted: Wed Dec 12, 2018 6:46 am
by Remon8399
Hi, I want to ask how to grab/pass the CURRENT speaker name into UI text component. :lol:

Not control by Subtitle Panel -> Standard UI Subtitle UI Element -> visibility (Only during content), because I want make sure Actor and Conversant portrait image and name are always show while talking. Then add the current speaker name to other side UI that show in the image that I shared.

Here is the image.

Re: [ASK] How to grab the current speaker name

Posted: Wed Dec 12, 2018 9:14 am
by Tony Li
Hi,

If I understand you correctly, assign Speaker Text to all of the subtitle panels' Portrait Name fields.

If that doesn't do what you want, you can write a small script with an OnConversationLine method. The property Subtitle.speakerInfo.Name contains the speaker's name. Example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class SetSpeakerText : MonoBehaviour {
    public UnityEngine.UI.Text speakerText; // Assign in inspector.
    void OnConversationLine(Subtitle subtitle) {
        speakerText.text = subtitle.speakerInfo.Name;
    }
}
Another option is to write a subclass of StandardUISubtitlePanel and override the SetContent method. Then use this subclass on your subtitle panels instead of StandardUISubtitlePanel.

Re: [ASK] How to grab the current speaker name

Posted: Wed Dec 12, 2018 9:31 am
by Remon8399
Thank you. That is what I want exactly.

Re: [ASK] How to grab the current speaker name

Posted: Wed Dec 12, 2018 9:42 am
by Tony Li
Happy to help!