Version: 2020.3
public int layer ;

描述

该游戏对象所在的层。

可用于有选择地从摄像机渲染 或者忽略射线投射。Unity 生成 32 个层。从 8 往上的层 未使用。可出于特定游戏原因而使用这些层。 层是在游戏开发期间被命名和使用的。单击 Editor 右上方 Layout 按钮可添加和查看层。

// Put the game object in the ignore raycast layer (2)

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { void Example() { gameObject.layer = 2; } }