- Home /
A way to set a custom camera.viewport background color?
You can easily setup the camera.backgroundColor in the inspector, but - when limiting the camera viewport - how to change the viewport background color from its default gray to anything else?
How would you do that? Put a GUI.Box or draw a gui coloured texture over it?
What do you mean by "limiting the camera viewport"? Do you mean making the viewport take up only part of the available screen space by setting its camera.rect
attribute through code or via the Inspector?
You should be able to set its camera.backgroundColor
attribute via code, and ensure that its camera.clearFlags
attribute is set to CameraClearFlags.SolidColor
.
In C# code for a script attached to the camera in question, it'd look like this:
camera.backgroundColor = Color.cyan; //set whatever colour you want
camera.clearFlags = CameraClearFlags.SolidColor;
I mean by setting its camera.pixelRect through code or via the Inspector exactly. That code works for the camera, not viewport background.
Answer by root8888 · Apr 25, 2014 at 04:53 AM
The best way that I have found to do this is to create another camera in your scene at the lowest depth and set that camera's background color to whatever you like. In my case, I chose white so the game fits in better on Facebook's layout.
Step by step instructions:
Choose GameObject -> Create Other -> Camera
Set Clear Flags to Solid Color
Set Background to whatever you like
Set Culling Mask to Nothing
Set Depth value to -2
Your answer
Follow this Question
Related Questions
Change the background color attribute of a camera in C#? 2 Answers
How can I create a gradient color background for my game, without using skybox? 2 Answers
Randomly Transition Camera Background Color? 2 Answers
How to randomly chenge camerabackground color every 5 seconds? 1 Answer
C# Randomize Background.Color Issues 1 Answer