Background of MainCamera (Unity C#)

* 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.

Leave a Comment