How Can i do Always Fading in-out Text?

Hello everyone, i want to make fading text like Mr jump (Tap to Play Text). But i did not. It is like this video:

Please can you help me?

Are you using the new UI system, with a Canvas?

If so, attach a CanvasGroup component to the Canvas that is a parent of all the graphics that make up your text (button, Text, bg image, etc). CanvasGroup as an ‘alpha’ value on it.

Then in a script, set a public variable for the CanvasGroup. And in it, during Update, ping pong a value from 0-1 at a speed. And set the alpha value with that.

Like this:

public class PingPongCanvasGroupAlpha : MonoBehaviour
{
   
    public CanvasGroup target;
    public float speed = 1f;
   
    private float _t = 0f;
   
    void Update()
    {
        _t += Time.deltaTime * speed;
        target.alpha = Mathf.PingPong(_t, 1f);
    }
   
}
1 Like

@1ht1baron

hi, if you do a search for “unity animate text alpha” you’ll find many examples, but most likely you have to customize those for your needs.

Also, if you want to keep it simple; add animator, and canvas group to your object (for example) and then animate alpha value.

EDIT: oops - didn’t refresh page. Was late.

1 Like

Thank you so much. It is working :slight_smile:

@1ht1baron

If you want to finetune the effect, you can also swap Mathf.PingPong from @lordofduct 's example to sine.

This way you get a non-linear wave like animation (my eye says that is the case with your example, it doesn’t have a “sharp” feel near its end…). Just try this with the code you have:

Mathf.Sin(Time.time * speed) * 0.5f + 0.5f;

This will give you a smooth wave like alpha transition that stays between 0-1.

1 Like