0
\$\begingroup\$

enter image description here

I want to select more layers for Raycast Mask at runtime when I click a button.

I tried GetComponent<XRRayInteractor>().raycastMask. but couldn't find an option to select more layers

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

This is a bitmask, so you can shift a 1 bit into the position corresponding to each layer's index, then use | (bitwise OR) to combine these into a mask with exactly those chosen bits set to 1 and the rest left at 0.

int firstLayer  = 1 << LayerMask.NameToLayer("First Layer Name Here");
int secondLayer = 1 << LayerMask.NameToLayer("Second Layer Name Here");
int thirdLayer  = 1 << LayerMask.NameToLayer("Third Layer Name Here");

GetComponent<XRRayInteractor>().raycastMask = firstLayer | secondLayer | thirdLayer;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .