unity3d Layers Layer usage


Example

Unity layers are similar to tags as in that they can be used to define objects that should be interacted with or should behave in a certain manner, however, layers are mainly used with functions in the Physics class: Unity Documentation - Physics

Layers are represented by an integer and can be passed to the functions in this manner:

using UnityEngine;
class LayerExample {

    public int layer;

    void Start()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, 5f, layer);
    }
}

Using a layer in this manner will include only Colliders whose GameObjects have the layer specified in the calculations done. This makes further logic simpler as well as improving performance.