I want to fade out an image, so I have a coroutine FadeOut()
. However, I want to have a separate image each time I call FadeOut.
If I try to do something like this:
IEnumerator FadeOut(GameObject image) {
SpriteRenderer render = image.GetComponent<SpriteRenderer>();
yield return null;
}
Ignoring all the color changing code which I took out, how do I make it so that I can save a separate cache for each image I add? I don't want to run GetComponent()
each frame, because I'm running on mobile and because I want to think of a clever way to stash the renderer.
For example, if I declare the renderer at the top like this:
private SpriteRenderer render;
and want to cache it on the first frame of the coroutine, there's the chance that calling FadeOut()
on another object will change the renderer to a new object and the first FadeOut()
will cancel.
Can I make the method static? Will that cache a private version of renderer?