So I am writing a script to fade a second image in and out on the title screen. Here what I have so far (and it works, just not as intended):
private Image lightImage;
// Use this for initialization
void Start () {
lightImage = GetComponent<Image>();
for (int i = 0; i < 1000; i++)
{
// fade to transparent over 500ms.
lightImage.CrossFadeAlpha(0.0f, 0.1f, false);
// and back over 500ms.
lightImage.CrossFadeAlpha(1.0f, 0.1f, false);
}
}
I have also tried to put this in FixedUpdate but I just can’t figure out how to continually make this change over time. I think I will have to use Time.DeltaTime but I’m just not sure how. Any help is appreciated.
Edit: Another attempt
private Image lightImage;
private float alpha;
// Use this for initialization
void Start ()
{
lightImage = GetComponent<Image>();
alpha = Time.deltaTime * 10;
}
void FixedUpdate()
{
// fade to transparent over 500ms.
lightImage.CrossFadeAlpha(0.0f, alpha, false);
// and back over 500ms.
lightImage.CrossFadeAlpha(1.0f, alpha, false);
}