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
0
Question by Giantbean · Feb 11, 2013 at 01:58 AM · cameralayersswapswapping

How do you dynamicly change a cameras culling mask based on an object selection?

I'm not sure how to even ask this question. I have been working on it all day and reading forums scripting reference pages and answers on this site but I'm just not understanding.

I need to set the camera to only look at a certain layer culling mask based on a gameObject selection.

Something like this:

 public var LayerName 
     //Make the code reusable when attached to different objects
     //by changing the visible layer in the inspector
 
 if(Input.GetMouseButton(1))//mouse over and left click a collider object
 {
 Camera.mySecondCam.cullingMask = LayerName;
 //Make the second cameras culling mask change to a preset layer name or number.
 }

The above code is not functional and is listed only for aid in explaining the end goal.

So I may need ray casting and I need to know what to code in the "layer name or number" section. I have looked into camera target swapping and using multiple cameras turning them off and on like light switches when parts of the main gameObject are selected. (each part has its own collider)

I have an object visible in the main camera and I have a second camera acting as a picture-in-picture view of selected object parts. The second camera is based on the MouseOrbitZoom camera found on the Unify Community Wiki. When parts of the main camera object are selected the second camera displays a close up copy (prefab) of the selected object.

For example if I had a car in the main cam I could select the door (layer 1 for example) and the second camera's culling mask layer should be set to that objects prefab layer (layer2) then I select the main cameras tire (Still layer 1) and the second camera needs to change to that objects prefab (Layer 3 for example)

I am not moving the camera so each object has a double that is set in a base location with the second camera targeted to view and rotate around any of the visible objects (Door or tire in this example). So long as I can change the culling mask layer based on different objects selected I should be able to accomplish my goal.

I hope that's clear enough to explain my issue. If it is not please feel free to ask for clarification.

Thanks in advance for any help.

Comment
Add comment · Show 3
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 Lockstep · Feb 11, 2013 at 02:28 AM 0
Share

This has already been answered: http://answers.unity3d.com/questions/8715/how-do-i-use-layermasks.html

avatar image Giantbean · Feb 11, 2013 at 02:47 AM 0
Share

Thanks I had not found that article. However I dont feel that really answered my question. Perhaps I'm just to tired to understand it at the moment and I will have to read it again in the morning.

On a Side note I found Bob Berkebile's "Layer masks Simplified" Script and tried to use:

 public class CameraOperator : $$anonymous$$onoBehaviour {
     public float LayerNum = 0;
     // Use this for initialization
     void Awake () {
     //Set a camera to only look at layer the set mask:
         if (Input.Get$$anonymous$$ouseButton(1))//leftclick
         { 
         camera.culling$$anonymous$$ask = Layer$$anonymous$$askHelper.OnlyIncluding( LayerNum );
         }
   }
 }

but I'm still not having any luck.

avatar image Giantbean · Feb 11, 2013 at 06:56 PM 0
Share

Yeah I read over the link Lockstep graciously sent and again while it's very informative it does note address my issue. I know how to change the culling mask and I can manually set my cameras mask without any issue. I understand the bit shift. $$anonymous$$y issue is I don't know how to make the code look for the layer I want to show when an object in the sceene is clicked on.

Think of this as a split screen. The full car in one window and parts in the other. I click on parts of the full car and should get close up views in the second window. I can get one part to view but how do I change from one part to another? I have each object in a named layer I just need to be able to change the cameras layer culling based on clicking gameObjects. Am I doing this completly wrong? Am I missing something in Lockstep's post? I'm new to program$$anonymous$$g but bit shift dosnt seem to be what I need as I already have culling maskes created.

1 Reply

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

Answer by Giantbean · Feb 11, 2013 at 09:36 PM

OK I was being stupid and asked the question the wrong way. What I wanted to do does not require culling masks as I can simply change the visibility of the item like a light switch.

I used Javascript:

 #pragma strict
  
     var linkedMesh : Renderer;
      
     function OnMouseDown()
      {
       linkedMesh.enabled = !linkedMesh.enabled;
      }

Now I just need to add the code to make other objects visibility turn off when this code is in use. A few more "Renderer" variables and I should be set.

Edit: Its all working. I added more "var linkedMesh(01-12) : Renderer;" lines for each item and set the layers that I did not want visable to "linkedMesh.enabled = false". Its not exactly what I wanted but its working. I also used culling layers on the cameras in the sceene but I set them manualy.

Comment
Add comment · Show 1 · 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 Giantbean · Sep 24, 2013 at 09:31 PM 0
Share

Another way to do this If anyone is still viewing this old post.

Use tags and layers something like this:

 //C# Unity class
 
 bool isClicked = false;
 GameObject baseObject;
 string obj_name;
 string layerName;
 
 //on start code and such
 
     void On$$anonymous$$ouseDown () {
          obj_name            = this.gameObject.name;
             baseObject          = GameObject.Find( obj_name );
             string obj_tag      = baseObject.gameObject.tag; 
 
 
  if (isClicked == false){
             switch (obj_tag)
             {    
     case "tag_tag1": // your tag name
         Show ("tag1"); //your layer names
         Hide ("tag2");
         Hide ("tag3");
         isClicked = true; 
 break;
     case "tag_tag2": // your tag name
         Hide ("tag1"); //your layer names
         Show ("tag2");
         Hide ("tag3");
         isClicked = true; 
 break;
     case "tag_tag3": // your tag name
         Hide ("tag1"); //your layer names
         Hide ("tag2");
         Show ("tag3");
         isClicked = true; 
 break;
     default:
 break;
 }
 else {
      switch (obj_tag){
     case "tag_tag1": // if a is a string
       Hide ("tag1");
           isClicked = false;
     break;
     case "tag_tag2": // if a is a string
       Hide ("tag2");
           isClicked = false;
     break;
     case "tag_tag3": // if a is a string
       Hide ("tag3");
           isClicked = false;
     break;
     default:
 break;
 }
 }

 

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

10 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

Related Questions

Changing the camera from first person to third person. 1 Answer

Bloom to Only effect Objects on UI layer ? 0 Answers

Can I render a single render but only with the objects that are not occluded by other objects (on other layers)? 1 Answer

Render tooltip on top of everything with MRTK 0 Answers

How do I get my camera to render 2 culling masks in scripts? 2 Answers


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