How to set random background images instead of colors?

Hi,

Currently I have 8 different background colors on my game.They are changing when game over and start again.This part is fine.But now I want to set random background images instead of colors.

This is my code right now to select colors

 // Initialize background color
        indexBackgroundColor = (int)Mathf.Round(Random.Range(0.0f, 6.0f));
        Camera.main.GetComponent<Camera>().backgroundColor = backgrounds[indexBackgroundColor];
        currentLevel = selectedLevel;
        currentLevelText.text = currentLevel + " / " + (myLevelGenerator.levelsManager.Length - 1);

Unity editor I have defined colors like this

87113-untitled.png

How can I accomplish this task (both unity editor side and code side)

Thanks

You’d need to set up a Canvas UI with a full-screen Image component to show the background. The Camera class doesn’t have a built-in way to clear to an image.

Then you just change your color array to a Texture or Sprite array, and apply that to the image component in the canvas where you apply the color to the camera.