Unity : LayerMask

0000 0000 0000 0000

We have in our example the EnemyLayer on the sixth Layer
and what happen “under the hood” is simply this

0000 0000 0010 0000

The sixth Layer is now change to 0 to 1, so from false to true, and this means that the Raycast can hit ONLY what there is on this Layer.

Important Note :

always WATCH OUT at what parameter the method ask to us.

This seems incredibly stupid, but is one of the most common error, like forgot to attach the script to the objects or to pass the objects in the editor.
I’m telling you this because normally Unity gives us an almost instant error and we can fix it.
But for example in this case we can literally go crazy finding the bug, because we don’t have any errors and things don’t work out.

--

--

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
Matteo Lo Piccolo

Matteo Lo Piccolo

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!