So in C# I’m trying to figure out how to just toggle the 9th layer.
So here’s the just of what I’m looking for…
if true
{
Camera.cullingMask actives layer 9
}
else
{
Camera.cullingMask deactivates layer 9
}
I need it to NOT interfere with the other layers that are currently activated or deactivated, I need it to toggle the 9th layer specifically.
As always, any help is appreciated.
PS. How the heck do you use “And” within an “If” statement?
I’ve tried things like
if varx == true && vary == true
but it treats it like I’m making an “Or”. Today’s just not my day
// Turn on the bit using an OR operation:
private void Show() {
camera.cullingMask |= 1 << LayerMask.NameToLayer("SomeLayer");
}
// Turn off the bit using an AND operation with the complement of the shifted int:
private void Hide() {
camera.cullingMask &= ~(1 << LayerMask.NameToLayer("SomeLayer"));
}
// Toggle the bit using a XOR operation:
private void Toggle() {
camera.cullingMask ^= 1 << LayerMask.NameToLayer("SomeLayer");
}
Oh I needed the extra set of parenthesis for it, lol.
I’m not entirely sure what you’re getting at with the main question though. Edit
Sorry miscommunication I suppose. I’m not looking to change the layers of any object. I’m looking to change what layers my camera is able to see. So to just turn a single cullingmask filter on or off without disturbing the other filters. Edit 2
Alright thanks. That really looks intimidating but I’ll sit down tomorrow and really try to wrap my head around it. Cheers.
Well I suppose as long as you’re here…
Could you explain what the “1” and the “<<” mean?
I’ve used them other areas but really it’s just trial and error.
Thanks, I really love how much better at Unity everybody else is compared to me. Makes it really easy to learn from others when there is a knowledgeable community.
Edit
Being a huge pain here I know, but could I get something that specifically turn it “On” and one that turns it “Off”. I know I asked for a toggle, I actually need the ability to turn it “On” (Even if it is on) or Off.