I have a canvas for UI, with an image the same size of the canvas. The Image
has an rgba
of 0,0,0,0
, making it invisible (because the a
is 0). I want to have the image fade into black from a script. Here is the code I am using:
public class NavigationC : MonoBehaviour {
public Image screen;
float fadeTime = 3f;
Color colorToFadeTo;
void StartGame()
{
colorToFadeTo = new Color(0f, 0f, 0f, 255f);
screen.CrossFadeColor(colorToFadeTo, fadeTime, true, true);
}
}
Now, this doesn't do anything when executed. But when I change the image's a
value manually in unity so that the image becomes visible, I can see the script changing the image's color. So the script does work, it just isn't visible because the a
value is not being changed by the script.
So how can I make the image fade from invisible to black?