A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.unity3d.com/Manual/../ScriptReference/../Manual/layermask-set.html below:

Unity - Manual: Set a layerMask

Introduction to layerMasks

Add a layer to a layerMask

Set a layerMask

This page explains how to set up a layerMask correctly so you can use it in API calls that use a serialized layerMask property.

Use a serialized layerMask property

The simplest way to set a layermask in the Unity Editor is to create a property that uses Unity’s LayerMask class. If the property is public or uses the SerializeField attribute, Unity provides an interface in the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary
that you can use to select which layers the layermask represents.

using UnityEngine;

public class LayerMaskExample : MonoBehaviour
{
    [SerializeField] private LayerMask layermask;
}
Convert from a layer

If you want to convert a layer to a layermask in a script at runtime, use the binary left-shift operator to left-shift 1 by the layer. The result is a layermask that represents the single layer.

using UnityEngine;

public class LayerExample : MonoBehaviour
{
    [SerializeField] private int layer = 10;
    private int layerAsLayerMask;

    private void Start()
    {
        layerAsLayerMask = (1 << layer);
    }
}
Additional resources

Introduction to layerMasks

Add a layer to a layerMask


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4