Hi!
I am working on some kind of transition system and I have used two lists. One lists stores the images so they can be reused and one list stores the current images that will be effected. But whenever I call this function the list removes from the list that stores the images and the list that stores the images that will be used. I have no idea why.
Here is some of my code:
public List<GameObject> blackImages = new List<GameObject>();
public List<GameObject> images = new List<GameObject>();
public void FadeOut()
{
images = blackImages;
StartCoroutine(FadeOutCo());
}
IEnumerator FadeOutCo()
{
foreach (GameObject image in images)
{
image.GetComponent<Image>().color = new Color(image.GetComponent<Image>().color.r, image.GetComponent<Image>().color.g, image.GetComponent<Image>().color.b, 0);
}
while(images.Count > 0)
{
GameObject imageToRemove = images[Random.Range(0, images.Count)];
imageToRemove.GetComponent<Image>().color = new Color(imageToRemove.GetComponent<Image>().color.r, imageToRemove.GetComponent<Image>().color.g, imageToRemove.GetComponent<Image>().color.b, 1);
images.Remove(imageToRemove);
yield return new WaitForSeconds(delay);
}
}
This was quite tricky to explain but I did my best.
Thanks in advance!