---
title: Unity でのレイヤーの使用
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/ja-jp/engine/6000.0/manual/working-with-gameobjects/layers/use
latest_url: https://docs.unity.com/ja-jp/engine/7000.0/manual/working-with-gameobjects/layers/use.md
last_updated: 2026-10-30
generated_at: 2026-11-17T09:32:01.667Z
locale: ja-jp
---

# Unity でのレイヤーの使用

> Unity でのレイヤーの一般的なアプリケーションを理解します。

レイヤーを使用して、プロジェクトとワークフローを最適化できます。レイヤーの一般的な使用例は以下のとおりです。

* レイヤーベースのレンダリング
* レイヤーベースの衝突

## カリングマスクとレイヤーの使用##use-the-camera-culling-mask-with-layers

カメラのカリングマスクを使用する場合は、特定のレイヤーまたは選択したレイヤーのオブジェクトのみをレンダリングすることができます。カリングマスクを変更するには、使用するカメラを選択し、Inspector ウィンドウで Editor ドロップダウンを選択します。レイヤーのチェックボックスを消去すると、シーンでレンダリングしません。

> **Note:**
>
> UI 要素とスクリーンスペースキャンバス子は例外で、関係なくレンダリングします。

## レイヤーを使ったレイ##ray-cast-with-layers

レイヤーを使用して、レイクトを指定できます。レイキャストでゲームオブジェクトを無視させるには、それを Ignore Raycast レイヤーに割り当てるか、[LayerMask](/engine/6000.0/manual/working-with-gameobjects/layers/and-layermasks.md) をレイキャスト API コールに渡します。

レイキャスト API コールに LayerMask を渡さない場合、Unity は Ignore Raycast を除くすべてのレイヤーに一致する [物理演算.DefaultRaycastLayers](/engine/6000.0/script-reference/unityengine/physics/defaultraycastlayers.md) を使用します。

物理演算.Raycast 関数はビットマスクを使用し、各ビットはレイヤーが Ray によって無視されるかどうかを判定します。layerMask のすべてのビットがオンの場合、レイはすべてのコライダーと衝突します。layerMask = 0 の場合、衝突はありません。

例えば、レイヤー 8 にレイをキャストする場合は、次のコードサンプルを参照してください。

```lang-cs
int layerMask = 1 << 8;

// Does the ray intersect any objects which are in layer 8?
if (Physics.Raycast(transform.position, Vector3.forward, Mathf.Infinity, layerMask))
{
    Debug.Log("The ray hit the player");
}
```

逆に、レイヤー 8 を除くすべてのレイヤーにレイを衝突させることができます。

```lang-cs
void Update ()
{
    // Bit shift the index of the layer (8) to get a bit mask
    int layerMask = 1 << 8;

    // This casts rays only against colliders in layer 8.
    // But to collide against everything except layer 8, use the ~ operator because it inverts a bitmask.
    layerMask = ~layerMask;

    RaycastHit hit;
    // Does the ray intersect any objects excluding layer 8.
    if (Physics.Raycast(transform.position, transform.TransformDirection (Vector3.forward), out hit, Mathf.Infinity, layerMask))
    {
        Debug.DrawRay(transform.position, transform.TransformDirection (Vector3.forward) * hit.distance, Color.yellow);
        Debug.Log("Did Hit");
    }
    else
    {
        Debug.DrawRay(transform.position, transform.TransformDirection (Vector3.forward) *1000, Color.white);
        Debug.Log("Did not Hit");
    }
}
```

> **Note:**
>
> Raycast 機能に layerMask を渡さなくても、IgnoreRaycast レイヤーを使用するコライダーは無視されます。

## 追加リソース##additional-resources

* [タグとレイヤー](/engine/6000.0/manual/unity-editor/editor-settings-reference/comp-manager-group/class-tag-manager.md)
* [Unity Learn:Unity Essentials](https://learn.unity.com/pathway/5f7bcab4edbc2a0023e9c38f)
* [レイヤーベースの衝突判定](/engine/6000.0/manual/physics-section/physics-overview/collision-section/collision-detection/layer-based-collision.md)
