title: Using coroutines to fade in/out TextMeshPro Text Element
body: <p>I am setting up a "scene intro" with some text saying 'Level 1' using TextMeshPro. I have created the text element in canvas and i am trying to find a way to make it fade in, then wait, and then fade out (Somewhat like what you see when you discover a new place in Skyrim).</p>
  
  <p>So far i tried a versatile solution so i can use the same script for other uses (eg not in the start of the scene, not only fade in etc).</p>
  
  <p><b>Using TMPro: </b></p>
  
  <pre><code>...
  using TMPro;
  ...
  </code></pre>
  
  <p><b>Start and declaration: </b></p>
  
  <pre><code>public class IntroFade : MonoBehaviour
  {
      [SerializeField] private TextMeshProUGUI textToUse;
      [SerializeField] private bool fadeIn = false;
      [SerializeField] private bool fadeOnStart = false;
      [SerializeField] private float timeMultiplier;
      private bool FadeIncomplete = false;
  
      private void Start()
      {
  
          if (fadeOnStart)
          {
              if (fadeIn)
              {
                  StartCoroutine(FadeInText(timeMultiplier, textToUse));
                  FadeIncomplete = true;
              }
              else
              {
  
                  StartCoroutine(FadeOutText(timeMultiplier, textToUse));
              }
          }
      }
  ...
  </code></pre>
  
  <p><b>Update in which i want to fadeout once fadein is done </b></p>
  
  <pre><code>
      private void Update()
      {
          if (FadeIncomplete)
          {
              StartCoroutine(FadeOutText(timeMultiplier, textToUse));
          }
      }
  
  
  </code></pre>
  
  <p><b>Corouritnes for the actual fading: </b></p>
  
  <pre><code>
  private IEnumerator FadeInText(float timeSpeed, TextMeshProUGUI text)
      {
          text.color = new Color(text.color.r, text.color.g, text.color.b, 0);
          while (text.color.a &lt; 1.0f)
          {
              text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a + (Time.deltaTime * timeSpeed));
              yield return null;
          }
      }
      private IEnumerator FadeOutText(float timeSpeed, TextMeshProUGUI text)
      {
          text.color = new Color(text.color.r, text.color.g, text.color.b, 1);
          while (text.color.a &gt; 0.0f)
          {
              text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a - (Time.deltaTime * timeSpeed));
              yield return null;
          }
      }
      public void FadeInText(float timeSpeed = -1.0f)
      {
          if (timeSpeed &lt;= 0.0f)
          {
              timeSpeed = timeMultiplier;
          }
          StartCoroutine(FadeInText(timeSpeed, textToUse));
      }
      public void FadeOutText(float timeSpeed = -1.0f)
      {
          if (timeSpeed &lt;= 0.0f)
          {
              timeSpeed = timeMultiplier;
          }
          StartCoroutine(FadeOutText(timeSpeed, textToUse));
      }
  
  </code></pre>
  
  <p>So what happens is it either fades in OR fades out depending on the Coroutine that starts first. I am not able to make it so it fades in, stays on screen for like 2 seconds and then fades out. </p>
  
  <p>I also tried fading in then creating a coroutine to waitforseconds and then call the fadeout coroutine but that didn't work either.</p>