Trying to fade a sprite via a coroutine. What am I doing wrong? Should I not be using coroutines? Right now it immediately turns to black instead of over time. (fader is the Sprite Renderer I’m trying to fade.)
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Door")) {
StartCoroutine("FadeIn", fader);
}
}
IEnumerator FadeIn(SpriteRenderer rend) {
for (int i = 0; i <= 255; i++) {
rend.color = new Color(rend.color.r, rend.color.g, rend.color.b, i);
yield return new WaitForSeconds(0.01f);
}
}