# SmartKeyHolder

### Core Features <a href="#core-features" id="core-features"></a>

#### Active Door Interaction <a href="#active-door-interaction" id="active-door-interaction"></a>

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 <a href="#key-interaction" id="key-interaction"></a>

`SmartKeyHolder` can hold multiple keys (`currentKeys`) and potentially use those keys to unlock or perform special actions on different `SmartDoor` objects.

#### Auto Door Open <a href="#auto-door-open" id="auto-door-open"></a>

`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 <a href="#manual-door-openclose-controls" id="manual-door-openclose-controls"></a>

The `SmartKeyHolder` also supports user input to manually open (`KeyCode.E`) or close (`KeyCode.R`) doors when within range.

#### Gizmo Visualisation <a href="#gizmo-visualisation" id="gizmo-visualisation"></a>

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 <a href="#usage" id="usage"></a>

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.

<figure><img src="https://3841237025-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTo1Wi5iIPqAsYGkTVfqo%2Fuploads%2FNtGbVFmKBBhD1Qvg6vGN%2FSmartKeyHolderComponent.jpg?alt=media&#x26;token=3f454089-6b04-458a-9053-e0ac44d906eb" alt=""><figcaption><p>SmarrttKeyHolder Component</p></figcaption></figure>

#### OwnedKeys <a href="#ownedkeys" id="ownedkeys"></a>

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 <a href="#display-gizmos" id="display-gizmos"></a>

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 <a href="#layer-mask" id="layer-mask"></a>

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 <a href="#max-distance" id="max-distance"></a>

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 <a href="#minnimum-reach-duration" id="minnimum-reach-duration"></a>

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 <a href="#open-on-reach" id="open-on-reach"></a>

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 <a href="#raycast-offset" id="raycast-offset"></a>

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cgpoly.io/door-system-documentation/advanced/components/smartkeyholder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
