I need to change the Culling Mask and Background Colors on certain game cameras. How would I go about doing that? Currently, the changes I make to the game cameras are overwritten by the main camera at runtime.
The MainCamera copies various properties of the GameCamera it's attached to, but for performance it doesn't do everything. You can get around this with a simple script attached to the MainCamera that copies over the rest, eg:
I have a similar issue where I need to use the Culling Mask on my cameras. I tried adding the above script to the MainCamera but I'm getting the following error:
Assets/NewBehaviourScript.cs(2,12): error CS0116: A namespace can only contain types and namespace declarations
Not sure if this is the same with the skybox but I could change the skybox easily with the following script. Object send message, custom, and put an integer (1).
This is a bit of an old topic, but I've found a need to copy the culling mask properties over from my game cameras and can't get this working. There are two things going on.
First, I'm getting an error on 'camera.cullingMask' and 'camera.backgroundColor' that says it is obsolete. However, when I change them to 'GetComponent<Camera>().cullingMask' or 'GetComponent<Camera>().backgroundColor', I get an error saying: '_Camera does not contain a definition for 'cullingMask' and no extension method 'cullingMask' accepting a first argument of type '_Camera' could be found. -- and the same error for 'backgroundColor'
I really REALLY don't want to mess around with the _Camera code. Am I missing an easier way of doing this?
Comments
using AC;
MainCamera mainCamera;
void Awake ()
{
mainCamera = GetComponent <MainCamera>();
}
void Update ()
{
if (mainCamera.attachedCamera)
{
camera.backgroundColor = mainCamera.attachedCamera.backgroundColor;
camera.cullingMask = mainCamera.attachedCamera.cullingMask;
}
}
using AC;
public class ChangeCullingMask : MonoBehaviour
{
MainCamera mainCamera;
void Awake ()
{
mainCamera = GetComponent <MainCamera>();
}
void Update ()
{
if (mainCamera.attachedCamera)
{
camera.backgroundColor = mainCamera.attachedCamera.backgroundColor;
camera.cullingMask = mainCamera.attachedCamera.cullingMask;
}
}
}