# LayerField

> Makes a layer selection field.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.5/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## LayerField(Rect, int, GUIStyle)

Makes a layer selection field.

```csharp
public static int LayerField(Rect position, int layer, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the field.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.5/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayerField (LayerField)](/api/media?file=/engine/6000.5/media/images/EditorGUILayerField.png)

*Layer field in an Editor Window.*

### Examples

```csharp
using UnityEngine;
using UnityEditor;


// Change the Tag and/or the layer of the selected GameObjects.

class EditorGUITagLayerField : EditorWindow
{
    string selectedTag = "";
    int selectedLayer = 0;

    [MenuItem("Examples/Tag - Layer for Selection")]
    static void Init()
    {
        var window = GetWindow<EditorGUITagLayerField>();
        window.position = new Rect(0, 0, 350, 70);
        window.Show();
    }

    void OnGUI()
    {
        selectedTag = EditorGUI.TagField(
            new Rect(3, 3, position.width / 2 - 6, 20),
            "New Tag:",
            selectedTag);

        selectedLayer = EditorGUI.LayerField(
            new Rect(position.width / 2 + 3, 3, position.width / 2 - 6, 20),
            "New Layer:",
            selectedLayer);

        if (Selection.activeGameObject)
        {
            if (GUI.Button(new Rect(3, 25, 90, 17), "Change Tags"))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    go.tag = selectedTag;
                }
            }

            if (GUI.Button(new Rect(position.width - 96, 25, 90, 17), "Change Layers"))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    go.layer = selectedLayer;
                }
            }
        }
    }

    void OnInspectorUpdate()
    {
        Repaint();
    }
}
```

## LayerField(Rect, string, int, GUIStyle)

Makes a layer selection field.

```csharp
public static int LayerField(Rect position, string label, int layer, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the field.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Optional label in front of the field.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.5/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayerField (LayerField)](/api/media?file=/engine/6000.5/media/images/EditorGUILayerField.png)

*Layer field in an Editor Window.*

### Examples

```csharp
using UnityEngine;
using UnityEditor;


// Change the Tag and/or the layer of the selected GameObjects.

class EditorGUITagLayerField : EditorWindow
{
    string selectedTag = "";
    int selectedLayer = 0;

    [MenuItem("Examples/Tag - Layer for Selection")]
    static void Init()
    {
        var window = GetWindow<EditorGUITagLayerField>();
        window.position = new Rect(0, 0, 350, 70);
        window.Show();
    }

    void OnGUI()
    {
        selectedTag = EditorGUI.TagField(
            new Rect(3, 3, position.width / 2 - 6, 20),
            "New Tag:",
            selectedTag);

        selectedLayer = EditorGUI.LayerField(
            new Rect(position.width / 2 + 3, 3, position.width / 2 - 6, 20),
            "New Layer:",
            selectedLayer);

        if (Selection.activeGameObject)
        {
            if (GUI.Button(new Rect(3, 25, 90, 17), "Change Tags"))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    go.tag = selectedTag;
                }
            }

            if (GUI.Button(new Rect(position.width - 96, 25, 90, 17), "Change Layers"))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    go.layer = selectedLayer;
                }
            }
        }
    }

    void OnInspectorUpdate()
    {
        Repaint();
    }
}
```

## LayerField(Rect, GUIContent, int, GUIStyle)

Makes a layer selection field.

```csharp
public static int LayerField(Rect position, GUIContent label, int layer, GUIStyle style)
```

### Parameters

**** (\[Rect]\(/engine/6000.5/script-reference/unityengine/rect)): Rectangle on the screen to use for the field.**** (\[GUIContent]\(/engine/6000.5/script-reference/unityengine/guicontent)): Optional label in front of the field.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The layer shown in the field.**** (\[GUIStyle]\(/engine/6000.5/script-reference/unityengine/guistyle)): Optional [GUIStyle](/engine/6000.5/script-reference/unityengine/guistyle.md).

### Returns

| Type                                                       | Description                     |
| ---------------------------------------------------------- | ------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The layer selected by the user. |

### Remarks

![EditorGUILayerField (LayerField)](/api/media?file=/engine/6000.5/media/images/EditorGUILayerField.png)

*Layer field in an Editor Window.*

### Examples

```csharp
using UnityEngine;
using UnityEditor;


// Change the Tag and/or the layer of the selected GameObjects.

class EditorGUITagLayerField : EditorWindow
{
    string selectedTag = "";
    int selectedLayer = 0;

    [MenuItem("Examples/Tag - Layer for Selection")]
    static void Init()
    {
        var window = GetWindow<EditorGUITagLayerField>();
        window.position = new Rect(0, 0, 350, 70);
        window.Show();
    }

    void OnGUI()
    {
        selectedTag = EditorGUI.TagField(
            new Rect(3, 3, position.width / 2 - 6, 20),
            "New Tag:",
            selectedTag);

        selectedLayer = EditorGUI.LayerField(
            new Rect(position.width / 2 + 3, 3, position.width / 2 - 6, 20),
            "New Layer:",
            selectedLayer);

        if (Selection.activeGameObject)
        {
            if (GUI.Button(new Rect(3, 25, 90, 17), "Change Tags"))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    go.tag = selectedTag;
                }
            }

            if (GUI.Button(new Rect(position.width - 96, 25, 90, 17), "Change Layers"))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    go.layer = selectedLayer;
                }
            }
        }
    }

    void OnInspectorUpdate()
    {
        Repaint();
    }
}
```
