Background of MainCamera (Unity C#)

Unity comes with a skybox functionality which you could use to create a background. It may take some reshaping but you should be able to reach the desired effect with the tutorial here.


** Edit 2020

Unity now has a simple way to do this, in Unity 2018.4+.

Follow these few steps to add texture as a camera background:

  1. Create a new Canvas that would hold your image.
  2. In that canvas, on Canvas component set:
    • Render Mode to Screen Space - Camera.
    • Render Camera to your main camera (drag&drop).
    • Plane Distance are the units, at which the background would render.
  3. Right-click on the newly created canvas and create an Image inside of it.
  4. On the newly created image on Image component:
    • Set Source Image to your desired background sprite.
  5. Stretch your image to the full screen size. You can do this as follows: in the Rect Transform of that image, there is a gray square in it with some arrows, and lines (saying stretch on top and left side), click it, a window with multiple squares would open, hold down the Alt and click the most bottom-right square.

Now you should have a tecture as camera background!


** old Unity

You can make it using a Skybox, or you can use a GUI Texture.

Here's how I made it some time before:

  1. Create a new camera (GameObject -> Create Other -> Camera), and name it "Background Camera".

  2. Create a new GUI Texture (GameObject -> Create Other -> GUI Texture), and name it "Background Image".

  3. Click the "Layer" dropdown menu in the Background Image's inspector pane, and select "Add Layer".

  4. In the next free "User Layer" slot, create a new layer name called "Background Image". This will be directly under the layer named "Terrain" if you haven't yet added any others.

  5. Select your Background Image in the hierarchy, and give it the desired texture, and set the x, y, width and height under "Pixel Inset" so that it fills the screen appropriately.

  6. Near the top of the inspector window, Use the layer dropdown menu to assign your "Background Image" layer that you defined earlier to this gameobject.

Now select your Background Camera in the hierarchy, and adjust these settings in the inspector:

  1. Un-Check Flare Layer and Audio Listener (but leave GUILayer enabled)

  2. Set Clear Flags to Solid Color

  3. Set Depth to -1

  4. Set Culling Mask, first to "Nothing", and then to "Background Image"

Now Select you other (main) camera, and in the inspector:

  1. Set its Clear Flags to "Depth Only"

  2. Click its culling mask setting, and un-check "Background Image". This should result in the culling mask displaying as "Mixed ..."

Voila, this should give you your GUI Texture rendered by your background camera, behind everything else rendered by your main camera. And for any other additional cameras (eg, other camera angles) that you want to use, just repeat the last two steps on them.


that other answer seems so out of date. I thought I'd share something newer. Just simply:

  • Right click your Main Camera, select UI -> Image.
  • Select your image and on the little box in Rect Transform where it says "stretch" and "stretch", click on that box. Now a menu will appear with a bunch of more boxes. Hold ALT and select the box furthest **Down Right **. This is the box with the blue arrows pointing at all directions.

Now you have fit your image to your canvas. In addition to this, you will need to fit your canvas to your camera.

  • Select your canvas. Within the Canvas' inspector, look for a component called Canvas. Change the Render Mode to Screen Space - Camera. Now it will ask you for a camera at the Render Camera box. Simply drag your Main Camera to Render Camera and voila, you have now a screen filled background without having 2 cameras lmao :)

Edit: Do not forget to turn off Raycasting for both the image and the canvas!

Tags:

Unity3D