Making an Interactive Prop
Props are able to trigger animations, much like the advanced avatar menu can. Triggers can be activated by the interaction button on your VR controllers or the appropriate key in desktop, by opening a menu page, by collider interactions, or by a wide number of other interactions.
This tutorial will give you some knowledge on how to make a simple prop interactive.
Prerequisites
- Knowledge of how to work with components
- Knowledge of how to work with GameObjects in the Scene Hierarchy
Making an Example Prop
To show you how the system works in a very simple, easy-to-understand way, we will be making a simple prop that changes from a cube to a sphere when the interaction trigger is pressed. It will do this by enabling a sphere and hiding a cube.
- Create an empty GameObject in your scene.
- Create a cube inside of the GameObject.
- Create a sphere inside of the GameObject.
- Disable the sphere.
- Make the GameObject a prop.
Making an Interactable
- Select the prop's root GameObject
- Add a CVR Interactable component to the GameObject.
- Change the Tooltip property to read "CHANGE ME".
Now we do the fun part.
Add a Trigger
A trigger is what activates a set of actions within the Interactable. A trigger can be activated by one of many events, most commonly by usage of the Interact input (trigger on VR sticks, mouse-left on desktop). For our purposes, we will use On Interact Down, which is activated when the interact key or grip is pushed down by the user. When the key or grip is raised, we will also capture On Interact Up to undo the changes we made in On Interact Down.
- Inside the CVR Interactable component, click Add Trigger
- For the Trigger property, select On Interact Down.
- Leave everything else alone.
Add an Action
An action is a task the game will perform when a trigger's conditions are met. A number of actions are available, but we will be making use of a simple Set Game Object Active action.
- Click Add Action.
- In the new Action, select Action Type to Set Game Object Active.
- Drag the cube inside the GameObject to Target.
- Set State to Disable.
- Create another action that enables the sphere.
Wrapping Up
Now to finish the prop.
- Create another trigger that is activated by On Interact Up.
- Inside this trigger, add an action that enables the cube.
- Add an action that disables the sphere.
And you're done! Upload to test.