Trigger box
Once components are added to an object, it's essential to configure the appropriate settings for them to function correctly. The Trigger Box component is a tool used to define spatial triggers, initiate events, and facilitate interactions between game objects without requiring physical collision. Trigger Box is a default component of each YahahaObject and can take the form of a sphere, box, or capsule.
The Visibility property controls whether the trigger box is visible in Edit Mode, which aids in positioning and sizing but doesn't affect gameplay. The Box/Sphere/Capsule property determines the shape and activation state of the trigger in-game; when enabled, the trigger is active, and when disabled, it's inactive during gameplay. You can adjust the trigger's position by modifying its center coordinates and alter its dimensions by changing its size parameters.
Triggering a narrator with trigger box
The Trigger Box is often used with the Event Trigger component to achieve interactions. This example demonstrates how to create a cube that triggers a voice-over when players enter its trigger box:
-
Create a cube by clicking the + icon in Scene Explorer and choosing 3D Object > Cube.
-
Add a trigger box to the cube: a. Select the cube and click the More icon to open its Properties window. b. Go to Trigger Box, click + Trigger, and select Box. c. Adjust the cube's size and center, ensuring the collider size is smaller than the trigger box.
-
Add and configure the Narrator component for the cube: a. Click Add Components in the cube's Properties window and select the Narrator component. b. Set up the Narrator component. For more information, see Narrator.
-
Add and configure the Event Trigger for the cube: a. Click Add Event Trigger at the bottom of the cube's Properties window. b. Set the trigger object to Self and OnTriggerEnter, leaving the condition groups empty. c. Add an action object to Self and set the function to ShowNarrator. For more details, see Event Trigger.
Now, test the trigger box in Play Mode: