unity-game-engineuser-interfacefadeleantween

How to fade TextMesh alpha with LeanTween?


I was looking for a way to fade the alpha value of TextMesh-Text in Unity, but I could not finde a solution online nor in the LeanTween Documentation.


Solution

  • After looking briefly through the API I guess a better way than introducing CanvasGroups just for fading one single text would rather be using LeanTwean.value for setting its color. CanvasGroup is a bit overkill here in my opinion.

    (example adopted from API)

    TextMeshProUGUI text;
    
    void Start()
    {
        text = GetComponent<TextMeshProUGUI>();
        var color = text.color;
        var fadeoutcolor = color;
        fadeoutcolor.a = 0;
        LeanTween.value(gameObject, updateValueExampleCallback, fadeoutcolor, color, 1f).setEase(LeanTweenType.easeOutElastic).setDelay(2f);
    }
    
    
    void updateValueExampleCallback(Color val)
    {
        text.color = val;
    }