How to use Unity and script to adjust the color and scale of grabbed objects while immersed in virtual reality
Scripts required: GenericLoader, SelectionManager, Selectable
VIMEO link: https://vimeo.com/730608128/ba3362da5c
Step by step (initial setup):
- If you don’t already have the Oculus Integration package installed, download it from the Oculus website (full instructions for this step can be found here).
- Set up your scene as desired, remember to include an object (full instructions for importing DICOM data objects into unity can be found here).
Step by step:
- Use the right-click menu to create an empty GameObject. Rename it Selection Manager. (This will make it so only one object can be selected at a time).
- In the inspector under tags & layers, add a tag for SelectionManager. You can make a new tag by clicking the + icon in the inspector (fig. 1).
- With the SelectionManager game object selected in the hierarchy, assign the SelectionManager tag by choosing it from the tag dropdown menu (fig. 2).
- Open the OVRPlayerController in the hierarchy, then OVRCameraRig, and select both hand anchors, which can be found in the TrackingSpace (fig. 3).
- With both hand anchors selected, give them a tag for hand in the inspector.
- Highlight the Selection Manager game object in the hierarchy, then click add component in the inspector and add a Selection Manager script (fig. 4).
- Next, select the object in the hierarchy that you want to be able to grab, click add component and add a Selectable script.
- You can now click the play button and use both controllers to manipulate object scale and color in-game.
Add a SelectionManager tag
Assign the SelectionManager tag to the Selection Manager game object
Find the left and right hand anchors in the OVRPlayerController and select both of them
You can find the selection manager script by typing in the add component search box
- Ctrl D (PC) can be used to duplicate objects in Unity
- Using the right-hand controller, the index trigger can be used to select an object in-game. Then, A and B buttons can be used to toggle through color transforms, and the right joystick can be used to alter the volume scale
- Objects will automatically deselect when a new one is selected