1
\$\begingroup\$

In Unity UI I have a TextMeshPro Button and some TextMeshPro Text like in the following image: enter image description here

Is there any function in a Tween Library like DOTween that could make the text look like its coming out from the left side then going back in? (not scaling). Or without a tweening library how could this be done?

Something like:

enter image description here

As @DMGregory pointed out, this could be understand in two ways

  1. coming out and in letter by letter or
  2. smooth transition, cutting the letters.

My aim was to achieve 2) - a smooth transition.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ I'm not familiar with this, but would moving your label and using a mask be a way to go? There are probably some folks with better approaches that'll chip in. \$\endgroup\$ Commented Apr 22, 2021 at 16:19
  • 2
    \$\begingroup\$ To clarify: do you want it to appear and disappear one full letter at a time like in your example diagram? Or should it move smoothly, occasionally cutting off or fading out half a letter as it crosses the threshold between shown and hidden? \$\endgroup\$ Commented Apr 22, 2021 at 16:58
  • \$\begingroup\$ @DMGregory a smooth transition, not letter by letter. \$\endgroup\$ Commented Apr 22, 2021 at 17:33
  • 1
    \$\begingroup\$ In that case, move the label and use a mask as Vaillancourt suggested. \$\endgroup\$ Commented Apr 22, 2021 at 17:37
  • \$\begingroup\$ Please share your solution as an Answer, rather than editing it into the bottom of your question. Try to share enough detail that a future reader would be able to solve the problem just from following your example. \$\endgroup\$ Commented Apr 22, 2021 at 18:13

1 Answer 1

1
\$\begingroup\$

Thank you for the help @Vaillancourt , @DMGregory and @Kevin - a mask works perfectly, will tune it further.

How I done it:

  1. Create a Panel near the Button
  2. Added a Rect Mask 2D as a component on the Panel

Now the children of the Panel (in this case some Text component) will only be visible when they are over the Panel

https://i.imgur.com/gfZjLhz.mp4

To move the text I used a tweening library (DoTween). If anyone is interested how the code of it would look:

private void HintSequence()
    {
        DOTween.Sequence()
            .Append(HintsQuestionMarkButton.transform.DOShakePosition(2.0f, 4.0f, 10, 50.0f, false, true))
            .AppendInterval(1.5f)
            .Append(HintsText.DOAnchorPos(new Vector2(0, 0.58f), 2.5f, false))
            .AppendInterval(1.5f)
            .Append(HintsText.DOAnchorPos(new Vector2(-170, 0.58f), 2.5f, false))
    }

private void Start()
    {
        InvokeRepeating("HintSequence", 2.0f, 25.0f);
    }

Final result: https://i.imgur.com/JJ28Q7G.mp4

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.