- Home /
Set transform layer
Hey there :D
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
Answer by PlasmaByte · Dec 28, 2013 at 11:30 PM
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
}
Excellent answer man! I am just curious if there is a way to set the layer of a transform in a similar manner as setting the layer of a gameobject.
eg.
gameObject.layer = 1;
I don't think you can have a separate layer for different components on the gameobject. What are you trying to achieve?
I've got a block building game, and I need the "Preview" block to be semi transparent and be in the "Ignore Raycast" layer. So I can see the block i am going to place, and still place it where required without my preview getting in the way.
Ah, I would use a separate object for the preview block and just change the mesh and material depending on the thing you currently want to build. Then instance the new block when you click confirm.
If your making a $$anonymous$$ecraft style game you won't want to have your blocks as separate objects anyway, far too resource intensive. You'll need to "chunk" it.
Your answer
Follow this Question
Related Questions
Finding all Objects by Layer within X Radius of Player? 1 Answer
Why wont Raycast wont ignore layer? 1 Answer
Raycasthit info only working the first time the object is hit 1 Answer
Usage of Layer masks, what am I doing wrong? 1 Answer
The Child Is Not Hovered When Passing The Parent's Collider 0 Answers