SmartKeyHolder
The SmartKeyHolder is a component that forms the core of the interaction system with doors in the game environment. It defines the ability to control smart doors and defines how and when your in-game
Core Features
Active Door Interaction
The SmartKeyHolder
has the ability to interact with a SmartDoor
when your character is close enough to it, based on a pre-defined reach distance. This distance can be specified and adjusted as per individual game requirements.
Key Interaction
SmartKeyHolder
can hold multiple keys (currentKeys
) and potentially use those keys to unlock or perform special actions on different SmartDoor
objects.
Auto Door Open
SmartKeyHolder
has a mechanism to auto-open the doors when the character is in reach. This can be enabled or disabled by setting the openDoorOnReach
property.
Manual Door Open/Close Controls
The SmartKeyHolder
also supports user input to manually open (KeyCode.E
) or close (KeyCode.R
) doors when within range.
Gizmo Visualisation
This setting allows the developer to visualize the SmartKeyHolder's
activity in the Unity 3D Editor itself, helping them to debug and understand the SmartKeyHolder's
interactions in the game world.
Usage
This component can be attached to any game object, but ideally, it should be attached to the character that will be interacting with various SmartDoor
-compatible doors in your game world. Once attached, you should configure its properties as per your requirements, like setting the maximum reach distance, deciding the raycastโs offset, specifying interaction keys, etc. Once set up, it provides an easy and efficient way to manage door interactions in your Unity game.

OwnedKeys
This is an array holding references to SmartKey
objects. These objects represent keys that can be used to interact with SmartDoor
objects in the game. Depending on the key used, different interactions or behaviors can take place with the SmartDoor
.
Display Gizmos
This boolean flag controls whether the interactive area of the SmartKeyHolder
(as determined by the raycast) should be visually represented in the Unity Editorโs Scene view. If set to true
, a visual debugging aid will show the reach of the raycast from the SmartKeyHolder
.
Layer Mask
This is used in filtering the kinds of objects the SmartKeyHolder's
raycast can interact with. Only objects on layers defined by layerMask
can be interacted with, offering useful control over what kinds of objects the SmartKeyHolder
can register.
Max. distance
This is the maximum distance from the SmartKeyHolder
within which a SmartDoor
can be interacted with. If a SmartDoor
is outside of this distance, it wonโt be registered by the SmartKeyHolder
.
Minnimum Reach Duration
This value is relevant when openDoorOnReach
is set to true
. It represents the minimum amount of time the player needs to be within the SmartKeyHolder's
maximum reach distance for a door to trigger and open.
Open on Reach
If this is set to true
, it will cause doors to automatically open when a player character moves within the maximumReachDistance
of the SmartKeyHolder
.
Raycast Offset
This defines an offset for the starting position of the raycast. It can be useful for fine-tuning the exact area where interaction is triggered, depending on the positioning of your SmartKeyHolder
GameObject.
Last updated
Was this helpful?