Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Hide Specific Layers from Camera?

Discussion in 'Scripting' started by Faestus, Jul 31, 2014.

  1. Faestus

    Faestus

    Joined:
    Jul 23, 2014
    Posts:
    68
    From what I know, cullingMask looks like this:
    Code (CSharp):
    1. camera.cullingMask = 1 | 2 | 3
    What I do not know, is how to add specific numbers to this integer.

    I tried turning it into a int[] but this doesn't work.

    I want to dynamically hide layers, and show certain layers.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Faestus

    Faestus

    Joined:
    Jul 23, 2014
    Posts:
    68
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  5. Faestus

    Faestus

    Joined:
    Jul 23, 2014
    Posts:
    68
    Well I tried this, but doesn't seem to work!


    Code (CSharp):
    1. LayerMask MASK = new LayerMask ();
    2.         for (int i=0; i<10; i++) {
    3.             if (i>FloorAt)
    4.             {
    5.                 MASK |= Physics.kIgnoreRaycastLayer;
    6.                 MASK = ~LayerMask.NameToLayer("layer"+i);
    7.             }
    8.                 }
    9.         camera.cullingMask = MASK;
    10.     }