Hello, I was hoping for some advice. I am attempting to use a CoRoutine to fade some text by lowering the Alpha on a CanvasGroup that theText is on. Once the weapon is select the Text should appear and then fade out after 1.5 seconds. I think it is partially working as the Text does disappear, but the fading effect is not noticable. Here are the relevant parts of my code, from Update -
public float gunNameFade = 1.5f;
public CanvasGroup canvasGroup;
public void NameGun()
{
UIController.instance.weaponText.text = activeGun.gunName + " eqipped";
UIController.instance.weaponText.gameObject.SetActive(true);
gunNameFade -= Time.deltaTime;
if (gunNameFade <= 0f)
{
StartCoroutine(TextFade(3f));
}
}
public IEnumerator TextFade(float time)
{
while (canvasGroup.alpha > 0)
{
canvasGroup.alpha -= Time.deltaTime / time;
yield return null;
}
}
If you’re looking for an easy non-code way to do stuff like this, there’s a free Asset in the Asset Store called LeanTween, which does this and a ton of other animation shenanigans.