Working with Layer Mask & Raycast

Limiting the Raycast to certain objects using Layer Mask

Setting up the Scene:

Since we can use the previous made projects for demonstrate the effects of the Layer mask, not much is required to setup. We will still need a cube platform and some objects on top.

Scripting:

To update our script (which we have used for the spawning of red spheres) that we currently are using that identifies objects via tags to identify objects with layer mask. We simply need to add onto the IF statement during the Physics condition.

As you can see, the layer 6 which is Target is set to all the Cylinders.

--

--

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

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
Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.