Continue Button to skip typewriter, then continue

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Rocky_Felix
Posts: 5
Joined: Tue May 04, 2021 10:59 pm

Continue Button to skip typewriter, then continue

Post by Rocky_Felix »

Hi Tony,

I've been designing my Dialogue UI and am getting it close to the way I want. I ran into an issue I can't find a solution to.

I want the continue button (which is now invisibly expanded across the whole screen) to skip the type writer effect, if the type writer is typing. If not, I want to continue.

Code: Select all

if (isTypeWriting)
    SkipToEndOfSegment();
else
    Continue();
Any idea?
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue Button to skip typewriter, then continue

Post by Tony Li »

Hi,

If you're basing your UI off the Standard Dialogue UI scripts, you can put a StandardUIContinueButtonFastForward component on the continue button, and configure the Button component's OnClick() method to call its OnFastForward() method. If you're not using Standard Dialogue UI, you can take a look at the StandardUIContinueButtonFastForward script and do the same thing that it does in your own script.
User avatar
Rocky_Felix
Posts: 5
Joined: Tue May 04, 2021 10:59 pm

Re: Continue Button to skip typewriter, then continue

Post by Rocky_Felix »

Yes! I think I'm close with this

Code: Select all

    public class DialogueContinueButtonConditionals : MonoBehaviour
    {
        [SerializeField] private StandardUIContinueButtonFastForward _fastForward;
        [SerializeField] private TextMeshProTypewriterEffect _typeWriter;

        private float _defaultCPS;

        public void OnContinueClick()
        {
            if (_typeWriter.isPlaying)
                _typeWriter.charactersPerSecond = 100;
            else
            {
                _fastForward.OnFastForward();
                _typeWriter.charactersPerSecond = _defaultCPS;
            }
        }

        private void Awake()
        {
            _defaultCPS = _typeWriter.charactersPerSecond;
        }
    }
It's not perfect, it acts a little funny, maybe a cached variable? (especially if the defaultCPS is low). But it work well enough so I'm happy with it :)
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue Button to skip typewriter, then continue

Post by Tony Li »

Ah, I misunderstood and thought you wanted to fast forward immediately to the end. If you want to speed up the typewriter effect, see this post for another example.
User avatar
Rocky_Felix
Posts: 5
Joined: Tue May 04, 2021 10:59 pm

Re: Continue Button to skip typewriter, then continue

Post by Rocky_Felix »

Tony Li wrote: Fri May 07, 2021 1:07 pm Ah, I misunderstood and thought you wanted to fast forward immediately to the end. If you want to speed up the typewriter effect, see this post for another example.
You were correct, I did, but then I got distracted in thinking that maybe I should just speed up the text very quickly. Your links helped! Thank you very much again :)
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Continue Button to skip typewriter, then continue

Post by Tony Li »

Glad to help! :-)
Post Reply