So i’ve found posts about using CrossFadeAlpha, so the solutions for that case didn’t work for me.
I just want to set a custom text color for a TextMeshProUGUI text when the button changes it’s state, so i inherited a class from Button to add some extra params for the text like normal and highlighted colors for the text, all works good, the button image fades, i can add some debug messages and te tmp is correct, the color taken in the “ChangeTMPColor” is good, but the function “CrossFadeColor” is just doing anything, any ideas?
Thanks!
public class ButtonColorText : UnityEngine.UI.Button {
TextMeshProUGUI tmp;
public Color textNormalColor;
public Color textHighlightedColor;
protected override void DoStateTransition(SelectionState state, bool instant) {
Color colorImage;
Color colorTMP;
switch (state) {
case Selectable.SelectionState.Normal:
colorImage = this.colors.normalColor;
colorTMP = textNormalColor;
break;
case Selectable.SelectionState.Highlighted:
colorImage = this.colors.highlightedColor;
colorTMP = textHighlightedColor;
break;
case Selectable.SelectionState.Pressed:
colorImage = this.colors.pressedColor;
colorTMP = this.colors.normalColor;
break;
case Selectable.SelectionState.Selected:
colorImage = this.colors.selectedColor;
colorTMP = this.colors.normalColor;
break;
case Selectable.SelectionState.Disabled:
colorImage = this.colors.disabledColor;
colorTMP = this.colors.normalColor;
break;
default:
colorImage = Color.black;
colorTMP = Color.black;
break;
}
if (base.gameObject.activeInHierarchy) {
switch (this.transition) {
case Selectable.Transition.ColorTint:
ChangeImageColor(colorImage * this.colors.colorMultiplier, instant);
ChangeTMPColor(colorTMP * this.colors.colorMultiplier, instant);
break;
}
}
}
private void ChangeImageColor(Color targetColor, bool instant) {
base.image.CrossFadeColor(targetColor, (!instant) ? this.colors.fadeDuration : 0f, true, true);
}
private void ChangeTMPColor(Color targetColor, bool instant) {
if (tmp == null)
tmp = GetComponentInChildren<TextMeshProUGUI>();
tmp.CrossFadeColor(targetColor, (!instant) ? this.colors.fadeDuration : 0f, true, true);
}