How to use layers in Unity?

Some time we need to assign objects to the same group so we can apply the same actions or effects to them or instead, prevent them from receiving these actions or effects. For this purpose, layers are commonly used by Cameras to render only a part of the scene, and by Lights to illuminate only parts of the scene. They can also be used by raycasting to selectively ignore colliders or to create collisions.

Creating Layers

To create a new layer, open the “Tags and Layers” window (Edit -> Project Settings -> Tags and Layers category).