Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active July 5, 2024 15:43
Show Gist options
  • Save unitycoder/17b82701f3e2f187eff9 to your computer and use it in GitHub Desktop.
Save unitycoder/17b82701f3e2f187eff9 to your computer and use it in GitHub Desktop.
LayerMask set initial value to "Default" or "Everything" or multiple layers
public LayerMask layerMask = 1 << 0; // default layer (0)
public LayerMask layerMask2 = ~0; // everything
public LayerMask layerMask2b = -1; // everything
public LayerMask layerMask3 = default;// nothing
public LayerMask layerMask4 = 0;// nothing
public LayerMask layerMask4b; // nothing
public LayerMask layerMask5 = 1 << 5;// layer 5 (UI)
public LayerMask layerMask6 = 1 << 2 | 1 << 5;// Ignore Raycast (Layer 2) AND UI (Layer 5)
public LayerMask layerMask7 = ~(1 << 4 | 1 << 5); // all except layer 4 and 5
public LayerMask layerMask8 = ~(1 << 4); // all except layer 4
@QuantumCalzone
Copy link

Thank you for this!

@gakkossphynx
Copy link

Amazing

@unitycoder
Copy link
Author

@unitycoder
Copy link
Author

Check if Layer Exists (by name), Assign Gameobject to layer using LayerMask
https://gist.github.com/unitycoder/65f604895f1699b92af1ba7762bfab45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment