Home>

Fade-in is simulated by increasing Text.color.a of Unity TextMeshPro by 0.01f.
I want to loop this in a coroutine and fade in the three texts in turn.
For some reason, the display speed becomes faster each time the first, second, and third are followed.

How can I change the first, second and third at a constant speed?

Runtime state

Applicable source code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class DisplayLookOnStatus: MonoBehaviour
{
    public TextMeshProUGUI [] Status;
    int i;
    float a;
    void Start ()
    {
        i = 0;
    }
    void Update ()
    {
        StartCoroutine (FadeIN ());
    }
    IEnumerator FadeIN ()
    {
        while (i<Status.Length)
        {
            Status [i] .color + = new Color (0, 0, 0, 0.01f);
            if (Status [i] .color.a>= 1)
            {
                i ++;
                Debug.Log (i);
            }
            yield return null;
        }
    }
}
  • Answer # 1

    Since Unity is not detailed, it may be removed, but since it is StartCoroutine with Update, FadeIN is running multiple times, so it may be that the addition of alpha value gets faster.
    What happens if I startCoroutine only once with Start?
    (It may be too small if the added value at that time is 0.01)