Page 1 of 1

Continue Button to skip typewriter, then continue

Posted: Fri May 07, 2021 1:45 am
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?

Re: Continue Button to skip typewriter, then continue

Posted: Fri May 07, 2021 9:11 am
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.

Re: Continue Button to skip typewriter, then continue

Posted: Fri May 07, 2021 10:49 am
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 :)

Re: Continue Button to skip typewriter, then continue

Posted: Fri May 07, 2021 1:07 pm
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.

Re: Continue Button to skip typewriter, then continue

Posted: Sat May 15, 2021 11:02 pm
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 :)

Re: Continue Button to skip typewriter, then continue

Posted: Sun May 16, 2021 7:46 am
by Tony Li
Glad to help! :-)