Opening a Door with a Command
Verificado com a versão: 2018.1
In the 3D Game Kit, Game Commands send a signal to other objects in Unity telling them to perform an action.
We’ll be opening a Door using a Pressure Pad. Let’s add a Door to the scene:
In the Project Window, go to Prefabs > Interactables
Find DoorSmall and drag it into the Scene View
The Gizmos on this object can be overwhelming. They can be adjusted to reveal only the Transform tools for the object or easy placement:
With DoorSmall selected in the Hierarchy, Navigate to the Inspector.
Click on the arrow on the Simple Translator Component to collapse it
Only the Transform tool for the object will now be visible.
- Position DoorSmall using the Transform Tools where you like.
Let’s add a Pressure Pad:
In the Project Window go to Prefabs > Interactables
Find PressurePad and click and drag it into the Scene View
Use the Transform Tools and place it near the door
Now let’s connect the PressurePad and DoorSmall so that the Door opens when Ellen steps on the Pressure Pad.
- In the Hierarchy click on PressurePad to select it
- In the Hierarchy, click and Drag DoorSmall to the Interactive Object slot in the Send on Trigger Enter Component on the PressurePad
In the Scene View there should be a white arrowed line showing a connection from PressurePad to DoorSmall.
- Press Play
The Pressure Pad will illuminate, descend and make the door open when Ellen steps on it.