Forum rules - please read before posting.

Subtitles - some scroll, some not

Is it possible to have one characters subtitles scroll and another one not? Rather than a blanket selection via Speech settings?

Comments

  • Provided both characters involved do not have visible subtitles at the same time, you can alter the value of the Speech Manager's Scroll speech text? option at runtime, based on which character is speaking:

    using UnityEngine;
    using AC;
    
    public class DynamicSubtitleScrolling : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnStartSpeech += StartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech -= StartSpeech; }
    
        private void StartSpeech (AC.Char speakingCharacter, string speechText, int lineID)
        {
            if (speakingCharacter == null) return;
            if (speakingCharacter.gameObject.name == "Tom")
            {
                AC.KickStarter.speechManager.scrollSubtitles = true;
            }
            else if (speakingCharacter.gameObject.name == "Jerry")
            {
                AC.KickStarter.speechManager.scrollSubtitles = false;
            }
        }
    
    }
    
  • ok thanks! So do I attach this to a player? Or gameobject in scene?

  • edited February 2022

    So I would have a different version of the script for each scene - where the .name == "xxxx" ? As these are prefab NPCs, and I would always want Narrator to be no scroll, and everyone else to be scroll. How would i do this?

    Or having one single script (in every scene) would I have to list every other non Narrator character in else if?

    Or is this through a call event?

  • @jamesfootlight, the script needs to be attached to a single object in the scene. It doesn't matter which object, as long as it is in the scene. If you aren't sure, this is super easy to test - just add the component, hit play and see what happens.

    Imho you'd manage to get things done a lot quicker if you took the time to learn a bit more about how C# works in Unity and also how to hook your own code to AC's EventManager.

    Basically, what Chris is doing with his script is to add the custom function StartSpeech as a listener to AC's OnStartSpeech function whenever the object the script is attached to is enabled in the scene (and removing it if it's disabled, to prevent memory leaks). This means that as long as the object is enabled in the scene, whenever AC displays a speech line, it will automatically run the code you write under StartSpeech.

    The example code Chris wrote enables scrolling if the speaker is Tom and disables it if it's Jerry. So you can easily adapt the script by checking if the narrator is the speaker and disabling scrolling if true. Then, instead of using an "else if" like Chris did, you can just use an "else" for any possibility other than the narrator.

  • edited February 2022

    So I updated my script to this:

    using UnityEngine;

    using AC;

    public class DynamicSubtitleScrolling : MonoBehaviour
    {

    private void OnEnable () { EventManager.OnStartSpeech += StartSpeech; }
    private void OnDisable () { EventManager.OnStartSpeech -= StartSpeech; }
    
    private void StartSpeech (AC.Char speakingCharacter, string speechText, int lineID)
    {
        if (speakingCharacter == null) return;
        if (speakingCharacter.gameObject.name == "Narrator")
        {
            AC.KickStarter.speechManager.scrollSubtitles = false;
        }
        else //if (speakingCharacter.gameObject.name == "Jerry")
        {
            AC.KickStarter.speechManager.scrollSubtitles = true;
        }
    }
    

    }

    But it would not work for me.

    My script is attached to a gameobject in the scene.

    My narrator is not usually in scene , as it takes up the narrator role. But even when I drop a NPC prefab of narrator in scene I cannot seem to get this to work.

  • In what way does it not work? What character speaks, and do subtitles scroll or not?

    AC considers "narration" to be any speech that doesn't have an assigned character. Narration has its own scrolling option that's independent from regular character subtitles.

  • Ah! So I got it working! my bad, thanks!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.