How to use layers in Unity?

// Check for “MyLayer 01” layer
LayerMask mask = LayerMask.GetMask("MyLayer 01");

// Does the ray intersect any objects which are in the “MyLayer 01” layer.
if (Physics.Raycast(transform.position, Vector3.forward, Mathf.Infinity, mask))
{
Debug.Log("The ray hits a gameObject in the layer named ‘MyLayer 01’ ”);
}

--

--

--

Computer Science Engineer and Cisco Instructor

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

HTTP Basic Authentication Sample

Don’t Waste Time On Boring Programming Lessons

How my journey in the open source community began (series 1/?) — First step

I do expect not to fail, cause I don't know how to swim!

Circle CI Orbs — Setup custom workflow and github checks

What they should had told me about Flask and Python since the beginning

The Liskov Substitution Principle Explained In .NET C#

The Liskov Substitution Principle Explained in .NET C#. Really understand the Liskov Substitution Principle of the SOLID principles in DotNet (.NET) CSharp (C#)

Microservices and how to analyse them

A Python Chatbot

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ouzani Abd Raouf

Ouzani Abd Raouf

Computer Science Engineer and Cisco Instructor

More from Medium

What are Unity Skyboxes?

Upgrading to the Universal Render Pipeline (URP)

Guide to Making a Beautiful Game: Occlusion Culling

The 5 best free Unity SDK for Mobile Unity 3D Developers