> 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). Agents can also search and read this documentation through its [MCP server](https://docs.convai.com/api-docs/~gitbook/mcp).

# 动态信息上下文

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

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

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

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FPcHnRayiITO9VCbTa8gk%2FUnity_DynamicInfoControllerComponent.png?alt=media&amp;token=dc8daf1e-53e7-435b-9b12-7b2cdddb7a5c" alt=""><figcaption></figcaption></figure>

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

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

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

### **示例场景**

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

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Ftl8cFeZ7jzyVaqmGKrLm%2FUnity_DynamicInfo_ExampleCode.png?alt=media&amp;token=a21a8f57-4fa0-4f47-aeaa-f46c45e8b35b" alt=""><figcaption></figcaption></figure>

### **对话示例**

下面提供一段示例对话，展示 NPC 如何根据玩家的动态生命值信息做出反应。通过动态更新玩家的生命值，NPC 可以给出贴合当前游戏情境、个性化且相关的回应。

### **总结**

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

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

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FR3LWMw0ihvoUuM9YU56G%2FUnity_DynamicInfoConversation.png?alt=media&amp;token=a0b095f1-de07-4ac8-8377-bfbcf8f8101b" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/unity-plugin/utilities/dynamic-config.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
