Hey everyone I did a brief test with Unity 4.6 and it seems that CrossFadeAlpha and CrossFadeColor aren’t working in Text Components.
Can someone let me know if I’m doing something wrong or if this is indeed a bug and, in that case, I’ll open the ticket.
Here is my code:
I added a text component and made it’s alpha 0. Doing this I should be able to fade-in the text.
gameObject.GetComponent<UnityEngine.UI.Text>().CrossFadeColor(Color.white, 1f, true, true);
//This also doesn't seem to work
gameObject.GetComponent<UnityEngine.UI.Text>().CrossFadeAlpha(1f, 1.5f, false);
Hi what color is the text to start with? (I’m guessing black). This crossfade fades the color on the CanvasRenderer. This means that if the text is black you will be doing “black * whatever color” which is still black.
If the text is white then it will be “white * whatever color” which is whatever color.
This is a common point of confusion — Graphic.CrossFadeAlpha does not operate on the color of the Graphic (the Image component in this case), like you might expect. Instead it operates on the alpha of the CanvasRenderer component, which is easy to overlook since it’s not a very accessible property. (It’s exposed only via the GetAlpha and SetAlpha methods, and not visible in the Inspector.)
So the best thing to do is call GetComponent().SetAlpha(0) in the Start method (no need to use CrossFadeAlpha here). Then you can use CrossFadeAlpha to tween it back in.