> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin/utilities/dynamic-config.md).

# 动态信息上下文

该 **动态信息** 该功能使您能够实时向 NPC 传递变量，使其能够根据游戏环境的变化动态做出反应。这些变量可以包括玩家当前生命值、物品栏中的物品，或上下文世界信息，从而大大增强交互性和沉浸感。

## **设置动态配置的分步指南**

首&#x5148;**，添加动态信息控制器** 组件到您的 Convai NPC 中。

<figure><img src="/files/c1ebb9a2a8f6f48d950f24faa4c6ed57f939a7c6" alt=""><figcaption></figcaption></figure>

创建一个新脚本，或使用现有脚本来定义一个变量，用于存储对 **动态信息控制器** 组件的引用，该组件已添加到您的 NPC 上。

### **示例：将玩家生命值传递给 NPC**

* **初始化动态信息**：在脚本的 **Start** 方法中，调用 `SetDynamicInfo` 方法，在 **动态信息控制器** 引用上。这样会设置 NPC 将要使用的动态信息。在这个示例中，我们将把玩家的生命值初始化为一个动态变量。
* **更新动态信息**：每当您需要向 NPC 更新新信息（例如玩家生命值变化）时，调用 `SetDynamicInfo` 动态信息控制器上的方法。

### **示例场景**

* 在游戏开始时，我们将玩家的生命值设为 100，并将此信息作为初始值发送给 NPC。
* 然后，当玩家受到伤害时（此处通过按下“K”键来模拟），我们会降低玩家的生命值并实时更新 **动态信息** ，以便 NPC 始终了解玩家当前的生命状态。

<figure><img src="/files/d39886837531d9fb1713052c5ecebfd2fabb555a" alt=""><figcaption></figcaption></figure>

### **示例对话**

下面，我们提供一个示例对话，展示 NPC 如何根据玩家的动态生命值信息做出反应。通过动态更新玩家的生命值，NPC 可以给出感觉更个性化且与当前游戏进程相关的回应。

### **总之**

添加 **动态信息控制器** 到您的 NPC。使用 `SetDynamicInfo` 在开始时初始化动态变量，并在需要更新时再次调用 `SetDynamicInfo` 。

此功能为创建能够实时响应游戏世界状态的 NPC 交互提供了强大的工具，从而为玩家带来更具沉浸感的体验。

<figure><img src="/files/fea644f7e051e9ffdaa50745a476d50fa5540818" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin/utilities/dynamic-config.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.
