Reputation:
I writing simple runner game
I have Main Camera and have Image. I want to set this Image as Main Camera background.
Upvotes: 20
Views: 91928
Reputation: 1
For Users using URP Camera, setting Background is easy.
In URP we have two types of cameras Base And Overlay. Its the first option of Camera Component called RENDER TYPE
For help you can refer to Image
Upvotes: 0
Reputation: 113
STEPS:
Upvotes: 0
Reputation: 2161
** 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:
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:
Create a new camera (GameObject -> Create Other -> Camera), and name it "Background Camera".
Create a new GUI Texture (GameObject -> Create Other -> GUI Texture), and name it "Background Image".
Click the "Layer" dropdown menu in the Background Image's inspector pane, and select "Add Layer".
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.
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.
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:
Un-Check Flare Layer and Audio Listener (but leave GUILayer enabled)
Set Clear Flags to Solid Color
Set Depth to -1
Set Culling Mask, first to "Nothing", and then to "Background Image"
Now Select you other (main) camera, and in the inspector:
Set its Clear Flags to "Depth Only"
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.
Upvotes: 67
Reputation: 904
that other answer seems so out of date. I thought I'd share something newer. Just simply:
Now you have fit your image to your canvas. In addition to this, you will need to fit your canvas to your camera.
Edit: Do not forget to turn off Raycasting for both the image and the canvas!
Upvotes: 28