- Home /
Changing camera with different culling mask
Hello, I need help with changing camera, I am building a function, that when I hold down or click on a keyboard key (like Tab), the camera changes to the second camera, which contains another set of Culling Mask. I'm using the FIrst Person Controller from the Standard Assets as I'm not very familiar with building FPS movement scripts (Walking, Running, Jumping) yet.
So far I tried attaching another camera to the First Person Controller with the alternate Culling Mask, when I click on the key, the camera changes. But the problem is the movement is having problems, like the horizontal movement for the character is being reversed (pressing left goes to the right and vice versa).
Is there any code to allow the changing of camera but still following the previous camera's position? Or is there any code to enable or disable culling mask for specific layers?
Thanks in advance
Answer by Paulius-Liekis · Jul 11, 2011 at 12:22 PM
Do one of the following:
Combine layer indices: http://answers.unity3d.com/questions/30843/how-to-compute-camera-culling-mask-via-script-to-s.html
(1 << LayerMask.NameToLayer("YourLayerName1")) | (1 << LayerMask.NameToLayer("YourLayerName2")) | ...
Define layerMask variable and set it from inspector (http://unity3d.com/support/documentation/ScriptReference/LayerMask.html)
I created 2 seperate Layer$$anonymous$$ask with contains 2 different culling mask value and assign it to the main camera's cullingmask and it works, thanks a lot :D