I came up with my own solution.
Instead of changing the alpha of the TextMesh-Component directly, I add a CanvasGroup to the Gameobject that holds my TextMesh-Component. Then I manipulate the alpha value of the CanvasGroup instead.
To use my example code:
- On your Canvas go: [RightClick] > UI > Text - TextMeshPro
- Attach my example Script to this Gameobject. (This creates the required CanvasGroup automatically)
- Press Play (Ctrl + P)
After a delay of 2 Seconds (because of.setDelay(2f) the Text should fade in.
Examplecode:
using UnityEngine;
using TMPro;
[RequireComponent(typeof(CanvasGroup))]
public class LeanTweenTextFade : MonoBehaviour
{
private void Start()
{
CanvasGroup canvasgroup = this.gameObject.GetComponent<CanvasGroup>();
TextMeshProUGUI infoTextTMPro = this.gameObject.GetComponent<TextMeshProUGUI>();
canvasgroup.alpha = 0f;
infoTextTMPro.text = "This Text should fade in.";
float duration = 1f;
LeanTween.alphaCanvas(canvasgroup, 1.0f, duration).setDelay(2f);
}
}
text.color.avalue over time without using LeanTween?