unity, UGUI Text fadeIn
错误写法:
Color color = m_text.GetComponent<Text> ().color;
Color startColor = new Color (color.r,color.g,color.b,0f);
Color endColor = new Color (color.r,color.g,color.b,1f);
m_text.GetComponent<Text> ().color = startColor;
m_text.GetComponent<Text> ().CrossFadeColor (endColor, durTime, false, true);
正确写法:
Color color = m_text.GetComponent<Text> ().color;
Color startColor = new Color (color.r,color.g,color.b,0f);
Color endColor = new Color (color.r,color.g,color.b,1f);
m_text.GetComponent<Text> ().CrossFadeColor (startColor, 0f, false, true);
m_text.GetComponent<Text> ().CrossFadeColor (endColor, durTime, false, true);
原因是m_text.GetComponent<Text> ().CrossFadeColor(targetColor, durTime, false, true)中targetColor会自动与Text的本来颜色相乘。
参考:http://forum.unity3d.com/threads/crossfadealpha-and-crossfadecolor-not-working-for-text-components.264473/