How to change text alpha with distance?

Hello! Looks simple, but there is complication. I have a canvas over object with animated UI text - animation already changes its alpha so text becomes transparent over time. And ALSO I need it to slowly vanish when player is too far. What is the best way to get it done?

Good day.

You need to do it by code, not by animation.

You just need to use

float distance == Vector3.Distance(position1, position2);

and then change the color depending ont he distance value by:

float TheAlphaValue = (Here you must calculate what alfa you want related to distance value)

Text.color = new Color (text.color.r, text.color.g, text.color.b, TheAlphaValue);

Try it, look for tutorials to understand everything, and try try try!

Bye!

Well, one idea you could try is to have a “max distance” that the player can walk from the object until the canvas is fully invisible. Get the current distance from the player and do something like (currentDist/maxDist) to get a percentage. This can be your distanceAlpha. Now you have two potential alpha values for the canvas (distanceAlpha and timerAlpha). Pick whichever one is the greatest (or least depending on how you do it) and apply only that alpha to the canvas.