So I have this line of code:
UIManager.instance.ShowHintMessage("You've unlocked <color=green>" + doorTarget.doorName + "</color> door.");
As you see, it’s calling a method called ShowHintMessage which receives a string parameter from a singleton. I use it very frequently for showing messages on screen and I never had an issue with it. Before seeing the code, I’ll like to go deeper on the situation.
I discovered literally a few days ago about the rich text function on UGUI text, so I decided to take a look a it a see how it worked. On this (“You’ve unlocked <color=green>” + doorTarget.doorName + “ door.”) line, I was trying to change the color of the “keyword” of my message, and well, it did change, but the behavior was very weird.
The message it’s displayed with a fade in/out effect. This is how it’s supposed to work:
but as you can see from the next gif, the keyword (doorTarget.doorName) it’s staying on screen even after the fade out effect:
*edit: I just recently noticed that the keyword appears even before the fade starts
Now, let’s take a look at the code:
public void ShowHintMessage(string message) {
StartCoroutine(IHintMessageCoroutine(message));
}
IEnumerator IHintMessageCoroutine(string pass) {
DOTween.Restart(hintMessageText);
//hintMessageText.canvasRenderer.SetAlpha(0f);
hintMessageText.text = pass;
hintMessageText.DOFade(1f, 1f);
//hintMessageText.CrossFadeAlpha(1f, 1f, true);
yield return new WaitForSeconds(2f);
hintMessageText.DOFade(0f, 1f);
//hintMessageText.CrossFadeAlpha(0f, 1f, true);
yield break;
}
I was first using DOTween for the fade in/out effect, but the issue mentioned before appeared, so I tried with CrossFadeAlpha because I thought that maybe it was a compatibility issue. Actually, if I use CrossFadeAlpha I get another problem, the text doesn’t even appear!
So, I’m not sure if that’s intended behavior (don’t remember seeing anything about it in the docs), or if it is a bug.