I need to know is there is a script that allows me to change the layers rendered because I need it for my start screen so if you click on options(for example) it will make all the other parts of the menu not render.
void OnMouseButtonUp()
{
if (isOptions == true) // Make sure to use “==” instead of “=” here!
{
Camera.main.cullingMask |= (1 << LayerMask.NameToLayer(“TheNameOfYourLayer”);
}
}
A brief explanation of this: Camera.cullingMask is a bitfield that represents which layers the camera will draw. That means if bit 0 is set, the camera will render layer 0. If bit 1 is set the camera will render layer 1, and so on.
The |= operator is a compound assignment operator, so the following two lines are equivalent:
a |= b;
a = a | b;
So, we use the bitshift operator (<<) to create an integer that has a single bit set that represents the layer we want to represent. If we’re rendering the 4th layer, that integer would look something like 0b00001000 (I’ve only included the last 8 bits here, because we don’t actually need to see an entire 32 bit binary literal).
By doing a bitwise or with the original culling mask, we are ensuring that the new layer we want is on, while all the other layers will have their original values.