Recipe 5 Unity6 - RosoVRgarden/VRgarden-tutorials GitHub Wiki
#VR recipe 5: XR Ray Interactor (Chameleon Wall)
The chameleon wall tutorial shows you how to use the <XR Ray Interactor> to change a material from a distance (as a remote control). In the hierarchy, find for the chameleon wall.
- The chameleon wall is a 3D cube in the shape of a wall. You need to set a layer so only certain object will interact using <XR Ray> Interaction. Click on the menu next to layer and select ‘Add Layer’. Then add a layer 8 and call it ‘direct xr’ and a layer 9 and call it ‘ray xr’.
- The next step is to add an <XR Grab Interactable> on the wall so we can interact with it. Interaction doesn’t mean moving something, it can be static. In order to make it static turn on the ‘Is Kinematic’ and turn off ‘Use Gravity’. Also, since it’s not moving, we can set the <XR Grab Interactable> Track Position, Rotation and Throw on Detach to off (0). Finally add a <Box Collider>.
- Since we use the right hand for direct interaction, we can use the left hand for <XR Ray> Interaction. The VR Ray is specific to VR as it allows you to interact with object at a distance. In our case, we use it as a remote control so we will turn off the Force Grab and Anchor Control. The Raycast Mask cast needs to be set to ‘ray vr’ to limit the objects we can use. The <XR Ray Interactor> also requires the <Line Renderer> and the <XR Interactor Line Visual> so you can see where you are aiming at.
- Finally, in order to change the materials, go back to the chameleon wall, check the <XR Grab Interactable> and look for the On Select Entered event. Click on + then drop the chameleon wall object, then choose MeshRenderer then MeshRenderer.material and drop a material of your choice (DryWallPainted is from the URP example scene).
On Select Exited event. Click on + then drop the chameleon wall object, then choose MeshRenderer then MeshRenderer.material and drop a material of your choice (Stud_Mat is from the URP example scene).
Now you should be able to change the material of the wall by pointing the ‘laser’ towards the wall. If you want more interaction, like changing more material, you will have to write your own code.