Page 1 of 1

Delay a subtitle from showing in code

Posted: Mon Jun 17, 2019 9:34 pm
by mgregoirelds
Hello,

I see that a question was asked about delaying a subtitle but the provided answer is with precreated commands of Dialogue System. How can I control when the subtitle is displayed if I'm making a custom command?

Here is my use-case that I would like to do:

1) Fade-in the text at the same time that the text is writing on screen
2) Enable continue button
3) Press Continue button
4) Fade-out current text
THEN 1) again

The problem that I get now is that upon pressing the continue button, it does not start the fade-out part. In fact, if I do the fade out part before the fade in, most of the text will already be written on screen upon my fade in. I don't really want that. Any way using code to hook some function to the continue button to actually fade out, then call my next dialogue for my fade in to start? Or delay when the text is starting to write on screen upon pressing the continue buttnon?

Re: Delay a subtitle from showing in code

Posted: Mon Jun 17, 2019 10:51 pm
by Tony Li
Hi Maxime,

One easy way is to use RPG Maker codes to pause before typing. For example:
  • Dialogue Text: "\.\.\.Hello, world."
The typewriter will pause for 3 seconds before typing "Hello, world.". By default "\." makes the typewriter pause for 1 second and "\," makes the typewriter pause for 0.25 second.

You could even use a script with an OnConversationLine method to add this to the subtitle text at runtime:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    if (string.IsNullOrEmpty(subtitle.formattedText.text)) return;
    subtitle.formattedText.text = @"\.\.\." + subtitle.formattedText.text;
}

A completely different idea is to point the continue button's OnClick() event to your own custom script method. In the method, fade out the current text. When it's faded out, call the dialogue UI's OnContinue() method -- or the subtitle panel's OnContinue() method if you're using the Standard Dialogue UI.

For example, point the continue button's OnClick() to this method on the StandardUISubtitlePanel:

Code: Select all

void MyCustomContinue()
{
    StartCoroutine(MyContinueCoroutine());
}

IEnumerator MyContinueCoroutine()
{
    var panel = GetComponent<StandardUISubtitlePanel>();
    panel.Close();
    do
    {
        yield return null;
    } while (panel.panelState != PanelState.Closed);
    panel.OnContinue();
}

Re: Delay a subtitle from showing in code

Posted: Tue Jun 18, 2019 8:55 pm
by mgregoirelds
Hello Tony! Great propositions, I'll test them out. Thanks a lot!

Re: Delay a subtitle from showing in code

Posted: Tue Jun 18, 2019 9:03 pm
by Tony Li
You're welcome! If those don't work out, let me know. I'm sure we can come up with a solution that works well for you.