Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by NutellaDaddy · Jan 11, 2014 at 04:35 AM · layersmain menu

How to change if layer is rendered by camera in script?

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Jan 11, 2014 at 04:36 AM 0
Share

You can change the Camera.culling$$anonymous$$ask at runtime.

avatar image NutellaDaddy · Jan 11, 2014 at 05:18 AM 0
Share

Can I change it to something like.

 void On$$anonymous$$ouseButtonUp()
 {
 //Already defined variables needed
     if(isOptions = true)
        {
         Camera.culling$$anonymous$$ask//what now?
        }
 
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by ncallaway · Jan 11, 2014 at 08:19 AM

 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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NutellaDaddy · Jan 12, 2014 at 03:16 AM 0
Share

How could I make it so a layer doesn't render? Could I use !! or whatever operator means don't because I need to turn off one layer after making this one active.

avatar image ncallaway · Jan 12, 2014 at 03:21 AM 1
Share

To turn off a specific layer you can use a similar technique using the &= operator. The basic idea is that you will create an integer with only the bit you want to turn off as a "0".

Then a bitwise and with the original value will turn off that bit, while leaving all the other bits in their original state.

You can create the desired field by using the complement operator. This inverts each of the bits in the value you give it. The final code looks something like:

 Camera.main.culling$$anonymous$$ask &= ~(1 << Layer$$anonymous$$ask.NameToLayer("TheNameOfYourLayer");

avatar image NutellaDaddy · Jan 12, 2014 at 03:23 AM 0
Share

You are the biggest help in the world man. Thanks! You should $$anonymous$$ch this stuff! You explain it perfectly.

avatar image ncallaway · Jan 12, 2014 at 03:34 AM 0
Share

Haha, glad to help!

avatar image NutellaDaddy · Jan 12, 2014 at 10:14 PM 0
Share

Wait one more thing. It says an object reference is needed to use camera.cullingmask. What do I need to do

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to find all objects in specific layer? 4 Answers

Main menu button loads main menu level but it is Frozen!!! 0 Answers

How to find layer instead of tags 3 Answers

Camera rendering help. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges