Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro Textmeshpro Text alpha does not react to new alpha assigned over time [Solved]

Discussion in 'UGUI & TextMesh Pro' started by simonlvschal, Nov 8, 2018.

  1. simonlvschal

    simonlvschal

    Joined:
    Nov 17, 2015
    Posts:
    266
    so as title suggest i am trying to make textmeshpro alpha change over time. but for some reason it doesn't exaclty do this.

    instead of going from 0-1 or 0-255 it does so instantly.

    this is the corutine

    Code (CSharp):
    1.  
    2. protected IEnumerator ShowZoneName(string zoneName,TextMeshProUGUI textMeshProUGUI,GameObject gameObject)
    3.     {
    4.         float t = 0;
    5.         Color startColor = new Color(255,255,255,0);
    6.         Color endColor = new Color(255,255,255,255);
    7.  
    8.         textMeshProUGUI.color = startColor;
    9.         textMeshProUGUI.text = zoneName;
    10.      
    11.         while (t < 1)
    12.         {
    13.             textMeshProUGUI.color = Color.Lerp(startColor, endColor, t);
    14.             t += Time.deltaTime / 5f;
    15.             Debug.Log(t);
    16.             yield return null;
    17.         }
    18.      
    19.     }

    Never mind solved it. i had to use Color32 instead
     
    Last edited: Nov 8, 2018
  2. jooij

    jooij

    Joined:
    Mar 27, 2017
    Posts:
    6
    I faced a similar problem.
    I avoided it with SetAllDirty.
     
  3. JohnnyGinard

    JohnnyGinard

    Joined:
    Feb 4, 2016
    Posts:
    2
    I was going mad. The alpha was doing weird stuff. Thank you for warning that we need to use 'Color32' instead of 'Color'! :D Literally spent an hour with this issue xD
     
  4. sbukotkinAUL

    sbukotkinAUL

    Joined:
    Jun 27, 2022
    Posts:
    2
    Spend an hour on it too. Renamed GameObject with this text and it just worked. Idk why.