Unity generate a 2D background

I’m making a game where the background depends on the colors of 2 players. The colors should fade from one side’s color to the other. Like a color gradient from left to right:

:

:

This should of course happen at game startup but I’m not sure the best way to generate the background for the Main camera.

Should I:

  1. Generate an image and add it to the scene as a sprite?
  2. Generate and add some material to an object in the scene? If so how?
  3. Is there a way to do this directly to the main camera’s default background color?

or

Is there a more efficient way?

Thanks

@RewForeN

  • if the color that is changing is simply a solid background color changing camera color would be the most efficient way of dealing with this.

cam.backgroundColor = Color.red;

  • if you are using a specific background image and that’s the only thing changing change the color of that background

m_SpriteRenderer.color = Color.red

  • while if the color of multiple object change as well create a sprite material and change it’s color (have a reference of it in your script don’t access it directly from the object as it’s a lighter process) but using this case keep in mind that the material color will not switch back on it’s own you will need to reset it every time you get in the game.

renderer.material.SetColor(“_Color”, Color.red);