How to create a laser pointer, compatible with INTERACT and Unity UI ?
You want to use some Unity UI while running your INTERACT simulation. Like our VR Menu, entirely made with Unity UI and customizable, you can trigger any action with Unity events.
But our UI pointer is by design only visible on our VR Menu or by choosing the mode "LaserGrab".
In this article, we present you a simple way to add a UI button and a permanent laser to interact with it.
Pre-requisites
- A Unity scene with an INTERACT simulation and VR player.
Add a Interactable UI Button
- Add a Canvas by doing GameObject > UI > Canvas
-
In its Inspector,
- Add the component Tracked Device Raycaster
- Change the Render Mode to World space. Then adapt the Width, Height and Position as desired.
- Drop the Main Camera in Event Camera.
-
Add a button as a child of the Canvas your created, resize it by changing the X and Y Scale's (Z not needed).
-
Add a Box Collider as a component of your button and make sure that it correctly fits your button.
Resize the collider
Directly typing the size into Box Collider to adjust will help at first.
-
You now need to give a instruction to the button when it is clicked. Go to Button and in the Button component add your instruction.
Make a permanent Laser
- In the Hierarchy, go to [PLayer_1] > VRMENU > Modes.
-
Copy the element VRLaserManipulator and paste it in the [Player_1]. You can rename it as VRLaserManipulator_2 and make it enabled.
-
In VRLaserManipulator_2 go to VR Pointer. In the component Laser Pointer > Options, check Active At Start. You can change the color of the new laser in the Line Renderer if wanted.
- In the Hierarchy, find the LaserManipulator and drop it in VRLaserManipulator_2 's VR Laser Manipulator Mode script in Manipulator.