Set transform layer

Hey there :smiley:

I am curious, is there a way to set a Transform’s layer?

I have a building preview object, which instantiated correctly(FINALLY), but I cannot set its layer to ignore raycast.

Thank you for reading, Sincerely,

Bakos133

You can set a gameobjects layer in the top right of the inspector window (just under the name). You can make new layers for your game if you want. To then ignore the layer you need to include a layer mask while raycasting (a binary number with 1 to include a layer and 0 to ignore it).

The following raycast ignores layer 8 (shift a 1 eight bits to the left and then invert it).

RaycastHit hit;
float distance = 1000;
int layerMask = ~(1<<8);
if (Physics.Raycast(ray, out hit,distance, layerMask)){

      //do cool stuff

}