I’m animating a button to fade in, it animates the alpha value of the button image and the child text colour alpha.
After the button has faded in, the animation stops playing (it is not set to loop)
Then when the user clicks on the button, I am using event trigger pointerdown to run a script on the text, a public function called OnChangeColour.
A string of the colour I want is passed to this.
With no animator on the button this works fine, but if it uses an animator, the colour can’t change.
Things I have tried:
-
If I target the animator and disable it on
OnChangeColour
the colour changes in the inspector but not on the text. -
Made a new empty state in animator and switch to that after the fader has played, doesn’t let text change colour still.
Fading in ui elements and doing mouse over buttons is 101 basic UI, how can we change colours after animating UI??
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ChangeColour : MonoBehaviour {
Color originalColor;
Text t;
void Start()
{
t = GetComponent<Text>();
originalColor = t.color;
}
public void OnChangeColour(string c)
{
if (c == "white")
{
t.color = Color.white;
}
if (c == "black")
{
t.color = Color.black;
}
}
void OnDisable()
{
t.color = originalColor;
}
}