Version: 2022.3
言語: 日本語
public int layer ;

説明

The layer the GameObject is in.

You can use Layers for selective rendering from cameras or to ignore Raycasts. Unity generates 32 layers, labelled with integers from 0 to 31 and reserves layers 0 to 5 for its own systems. You can use layers 5 and above. To add or view a layer, click the Layout button in the top-right of the Editor window.

// Put the GameObject in the ignore raycast layer (2)

using UnityEngine;

[ExecuteInEditMode] public class ExampleClass : MonoBehaviour { void Awake() { //gameObject.layer uses only integers, but we can turn a layer name into a layer integer using LayerMask.NameToLayer() int LayerIgnoreRaycast = LayerMask.NameToLayer("Ignore Raycast"); gameObject.layer = LayerIgnoreRaycast; Debug.Log("Current layer: " + gameObject.layer); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961