- Home /
How to set the editor's layer mask from script?
I need to gain access to the editor's layer mask to switch between some layer patterns. The idea is to have few layers for the game and few for the gui. Switching between them manually is a waste of time (especially if there are number of layers). Moreover it would be great to be able to specify the layer mask for each scene view window. This would allow to have a game editing window and a gui editing window. Any idea?
Answer by mbenn250 · Dec 15, 2015 at 08:57 AM
I do not entirely understand your question, but the way that one sets layer mask variables via script is by using a bitwise operator: 1<<. For example, if I wanted to linecast to only the layer "Enemies," I would say Physics.Linecast (Vector3.zero, Vector3.one, 1 << LayerMask.NameToLayer("Enemies")); What this code does is make the layer into a string of 1s and 0s, which in turn are used to check layers.
Answer by Ejlersen · Mar 12, 2021 at 02:57 PM
If anyone else finds this. You can do this by changing:
UnityEditor.Tools.visibleLayers
There is also one for locking layers:
UnityEditor.Tools.lockedLayers