You can interact with certain objects in an experience to trigger actions and effects. Interactive objects are created using Sansar's script API, and act as input controls for those API scripts. Some examples of interactive objects might be: a door that opens when you click it, or a button that plays an audio clip.
Using interactive objects
|Interactive objects highlight green when you move your mouse cursor over them or look at them in VR. This particular interactive object also displays the prompt text "Click Me!" when highlighted.|
In desktop mode
To use an interactive object in desktop mode, your avatar must be within 3 meters of it. When you move your mouse cursor over the object, it highlights green and some "prompt" text (if defined by the API script) may appear. Click the object to interact with it.
To use an interactive object in VR mode, look at it and point your VR controller at it to highlight it. Then, tap the "grab" trigger to interact with the object.
Creating interactive objects
Interactive objects are created using the Sansar script API.
The following API documentation is specific to interaction:
- Interaction class - Contains methods for reading and setting the interactive properties of the scripted object.
- InteractionData class - Handler for Interaction events. Can provide data on any interaction events that occur, including information such as who interacted with the object and where they touched the object.
|Tip: InteractionData can determine where the object was touched, so it is possible to create a single interactive object that triggers multiple effects. One way to achieve this would be to texture the object with multiple images of buttons and then use the API to detect when a touch occurs inside one of the designated button areas.|
|Note: A dynamic object cannot be both interactive and grabbable. If a dynamic object becomes interactive, it can no longer be grabbed using VR controllers or the mouse.|
The following example script is also included in the Sansar client's install directory, along with a full set of current API documentation. See Working with scripts for full details on the location and how to add scripts to an object:
- InteractionExample.cs - Click the object to make its interaction prompt show data about the interaction.