Advertisement
Caminhoneiro

LayerMask play

Apr 15th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CamCullingMaskController : MonoBehaviour
  6. {
  7.     [SerializeField] List<string> layerName;
  8.     [SerializeField] Camera camCustomCullingMask;
  9.     [SerializeField] GameObject objToHide;
  10.  
  11.     private int objLayer;
  12.  
  13.     void Start()
  14.     {
  15.         objLayer = objToHide.layer;
  16.  
  17.  
  18.         //Hide();
  19.         //CustomCamLayerMask();
  20.     }
  21.    
  22.  
  23.     void Update()
  24.     {
  25.         if(Input.GetKeyDown(KeyCode.S))
  26.             Toggle();
  27.  
  28.         print(objLayer);
  29.     }
  30.  
  31.     // Turn on the bit using an OR operation:
  32.     private void Show()
  33.     {
  34.         camCustomCullingMask.cullingMask |= 1 << LayerMask.NameToLayer("Water");
  35.     }
  36.  
  37.     // Turn off the bit using an AND operation with the complement of the shifted int:
  38.     private void Hide()
  39.     {
  40.         string objLayerName = LayerMask.LayerToName(objLayer);
  41.         camCustomCullingMask.cullingMask &= ~(1 << LayerMask.NameToLayer(objLayerName));
  42.     }
  43.  
  44.     // Toggle the bit using a XOR operation:
  45.     private void Toggle()
  46.     {
  47.         camCustomCullingMask.cullingMask ^= 1 << LayerMask.NameToLayer("Water");
  48.     }
  49.  
  50.     private void Hide2()
  51.     {
  52.         camCustomCullingMask.cullingMask = (1 << LayerMask.NameToLayer("Water"));
  53.     }
  54.  
  55.     void CustomCamLayerMask()
  56.     {
  57.         camCustomCullingMask.cullingMask = (1 << LayerMask.NameToLayer("TransparentFX")) | (1 >> LayerMask.NameToLayer("UI")) |
  58.             (1 >> LayerMask.NameToLayer("Water")) | (1 >> LayerMask.NameToLayer("Default"));
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement