I’ve set up a canvas with a bit of text that should update, appear, and then fade out when you pick up an item unlock. All of this works, EXCEPT… only the first time. After that, the alpha refuses to go back to 1, so it can only appear once.
void OnTriggerEnter(Collider obj)
{
if (obj.gameObject.name == "Player")
{
// play pickup audio
AudioSource.PlayClipAtPoint(pickup, transform.position, 0.05f);
// Remove this item from the locked items list
GameControl.lockedItems.RemoveAt(itemIndex);
// Update item unlocked message
itemUnlockedText.text = itemName + " unlocked!";
// Set up text color with alpha of 1 (starts at 0 by default)
textColor = itemUnlockedText.color;
textColor.a = 1f; // Need to first indirectly set alpha, then assign to the text object
itemUnlockedText.color = textColor;
itemUnlockedText.CrossFadeAlpha(0, 1.5f, false); // Immediately start fading
// Destroy this game object
Destroy(this.gameObject);
}
}
I’ve tried a bunch of different techniques for fading the alpha, and they all work, but they all refuse to allow me to set it back to 1 again the next time the player picks up one of these objects.