I am trying to script the selection of a random background image on my canvas from an array of background images. I’ve tried a couple of things so far. Here is my current attempt:
public class BackgroundChanger : MonoBehaviour {
private Image background;
[SerializeField]
private List<Image> bgImage = new List<Image>();
void Start ()
{
background = GetComponent<Image>();
Image randomBG = bgImage[Random.Range(0, bgImage.Count)];
background = randomBG;
}
In this attempt, I am not able to add my Images to my Array in Unity. I have also tried using Sprite instead but that doesn’t seem to change the background as desired. Any help is appreciated.