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

# 将动作添加到你的角色

遵循现有项目保留的旧版 Unity 动作工作流，并查找当前的 Convai Unity SDK 角色动作迁移指南。

此页面保留了旧版 Unity 操作工作流，供仍在使用旧版 Convai 集成的项目参考。

{% hint style="warning" %}
**已于 2026 年 8 月 26 日弃用。** 请参阅当前 Convai Unity SDK 文档中的 [角色操作](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/character-actions.md) 。此页面仍供尚未迁移的项目使用。
{% endhint %}

## 设置操作配置

1. 在层级视图中选择 Convai NPC 角色。
2. 向下滚动，找到附加到角色上的 ConvaiNPC 脚本。
3. 点击“添加组件”按钮。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fb06DsiOiHzNt8yLiXhVe%2Fimage.png?alt=media&amp;token=f511980d-6b14-45b8-a339-b0c51d1c3f32" alt="Unity Inspector with the Add Component control for the selected character" width="438"><figcaption></figcaption></figure>

4. 使用复选框将操作脚本添加到 NPC Actions。
5. 点击“应用更改”以确认。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FfDgdUhcTl2aIFHfrvInd%2Fimage.png?alt=media&amp;token=88ed20a6-f14d-429e-b6be-5a00a360f6e5" alt="Legacy NPC Actions setup with the action script selected" width="563"><figcaption></figcaption></figure>

## 预定义操作

Convai 提供预定义操作，方便快速开始。

1. 点击“+”按钮以添加新操作。
2. 在下拉菜单中选择“移动到”。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FqeGC7yKbbge4o5HuRLzF%2Fimage.png?alt=media&amp;token=f95b2865-ea80-4e90-b185-ec289c8227a1" alt="Legacy action configuration dropdown with Move To selected"><figcaption></figcaption></figure>

3. 将操作名称设为“Move To”（名称不必与所选操作名称一致）。
4. 暂时将 Animation Name 字段留空。

重复上述步骤，添加“Pickup”和“Drop”等其他操作。

### 在场景中添加对象

1. 在场景中添加任意可交互对象，例如球体、立方体或岩石。
2. 调整对象大小并将其放置在场景中。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FdaYRkOuVDOH5fCCjKf3H%2Fimage.png?alt=media&amp;token=a3ccc56f-05a2-43b7-80c2-d979e5858b48" alt="An interactable object placed in the Unity scene"><figcaption></figcaption></figure>

### 添加 Convai Interactables Data 脚本

* 创建一个空的 GameObject，并将其命名为“Convai Interactables”。
* 将 Convai Interactables Data 脚本附加到此 GameObject。
* 点击“+”按钮并附加相应的 GameObject，将角色和对象添加到脚本中。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FeozeOhx4vjvOAoHA6ydg%2Fimage.png?alt=media&amp;token=a19125de-bccd-451f-85de-b310736ccb03" alt="Legacy Convai Interactables Data component with character and object lists"><figcaption><p>Convai Interactables 设置</p></figcaption></figure>

* 将“There”对象添加到 Objects 列表中，以便使用 Dynamic Move Target 指示器。<br>

  <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F4sKwUATtSeYDQ2zuCbvv%2Fimage.png?alt=media&amp;token=7841f472-ec46-49f2-9087-93d5f266355a" alt="There object added to the legacy interactable objects list"><figcaption></figcaption></figure>
* 添加 [Dynamic Move Target Indicator](#adding-a-dynamic-move-target-indicator) 并为你的 NPC 设置 [NavMesh agent](#setting-up-navmesh) 。

### 设置 NavMesh

为确保 NPC 能够在场景中导航：

1. **烘焙 NavMesh** 如果尚未为场景执行此操作，请按以下步骤操作：
   * 前往 **Window > AI > Navigation**.
   * 在 **Navigation** 窗口的 **Bake** 选项卡中，根据需要调整设置。
   * 点击 **“烘焙”** 以生成 NavMesh。
2. 确保 NPC 角色具有 **NavMeshAgent** 组件：

   * 如果尚未附加，请点击 **“添加组件”** 并搜索 **NavMeshAgent**.
   * 根据 NPC 的需求调整 **Agent Radius、Speed，** 以及其他参数。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FBkCZTRp7by9bCs0mDAo6%2Fimage.png?alt=media&amp;token=056817c4-dc1c-49cc-9cb0-ebda17ff67f9" alt="NavMeshAgent settings on the legacy Convai character"><figcaption></figcaption></figure>

### 添加动态移动目标指示器

要直观显示 NPC 将要移动到的位置：

* 在场景中创建一个新的空 GameObject 并为其命名，或者使用名为 **Dynamic Move Target Indicator。**
* 将此 **Move Target Indicator** 关联到 NPC 的动作脚本，这样当你将光标指向地面并让 NPC 移动到“那里”时，指示器就会动态更新。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FISOT45TZnSaq6QVxdAvn%2Fimage.png?alt=media&amp;token=5af4dea9-c89b-49e4-b226-06f4d7f80864" alt="Dynamic Move Target Indicator positioned in the Unity scene"><figcaption></figcaption></figure>

### 测试设置

1. 点击“播放”以启动场景。
2. 对 NPC 说：“把盒子拿给我。”
3. 如果设置正确，NPC 应该会走到盒子旁边并把它拿给你。

{% hint style="warning" %}
此功能目前仍处于实验阶段，可能会出现异常。欢迎试用并向我们提供反馈。
{% endhint %}

## 在 Convai 中为 Unity NPC 添加自定义动作

### 创建动画动作

让 NPC 执行跳舞等自定义动作。

### 仅需动画的动作

1. 在我们的插件中找到舞蹈动画文件。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FcV6kdXXF9MBgQhd3Qs9E%2Fimage.png?alt=media&amp;token=73e6cffa-4185-4424-b3b4-914e1078e51f" alt="Dance animation asset selected in the Unity Project window"><figcaption></figcaption></figure>
2. 将此动画添加到 NPC 的动作中。

### 设置 Animator Controller

1. 在 Inspector 窗口中打开 Animator Controller。
2. 将舞蹈动画拖放到控制器上，创建一个名为“Dancing”的新节点。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FZhDi7oDCUWqNW9EBO4ra%2Fimage.png?alt=media&amp;token=f02bfe87-d7df-4931-8b9b-9815a03a90c2" alt="Animator Controller with a Dancing animation state"><figcaption></figcaption></figure>

### 添加自定义动画动作

1. 转到附加在 Convai NPC 上的 Action Handler Script。
2. 添加一个名为“Dancing”的新动作。
3. 在 Animation Name 字段中输入“Dancing”（必须与 Animator Controller 节点名称完全一致）。
4. 将枚举保留为“None”。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FHC7yf3x78rEu3THtdAhh%2Fimage.png?alt=media&amp;token=32912565-538d-496f-ba04-9c24ee37b400" alt="Legacy action handler configured with a Dancing action"><figcaption></figcaption></figure>

### 测试自定义动作

1. 点击“播放”以启动场景。
2. 对 NPC 说：“给我展示一个舞步”，NPC 就应该开始跳舞。

## 在 Unity 中使用 Convai 创建复杂的自定义动作：扔石头

### 定义投掷动作

为 NPC 添加投掷等高级自定义动作。

### 动画要求

1. 从 Mixamo 或其他你喜欢的地方获取一个 [投掷动画](https://www.mixamo.com/#/?page=1\&query=throw) 即可。
2. 将其导入 Unity。

### 设置 Animator Controller

1. 将投掷动画拖放到控制器上，创建一个名为“Throwing”的新节点。（请按照 [#action-that-only-requires-an-animation](#action-that-only-requires-an-animation "mention"))

### Action Handler Script Setup

1. 将“Throw”枚举添加到脚本中。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FdNNjyI4ZVIAvAyZAFfJ4%2Fimage.png?alt=media&amp;token=45926fa9-7e05-49ee-b2c5-f501b8c367f1" alt="Legacy action handler source with a Throw enum entry"><figcaption></figcaption></figure>
2. 在“Do Action”函数中，为投掷动作添加一个 switch 分支。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fbk2UBgs2ot79NGbptxXO%2Fimage.png?alt=media&amp;token=6153a10b-c6c6-4b0f-8e81-cfe336fc09b2" alt="Legacy Do Action switch with a Throw case"><figcaption></figcaption></figure>
3. 定义“Throw()”函数。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F4Cz4i2y6R1pKHsf50Oiy%2Fimage.png?alt=media&amp;token=29f8862f-b09f-4dfb-8260-1deab56a8e52" alt="Legacy action handler source defining the Throw function"><figcaption></figcaption></figure>

### 添加投掷动作

1. 添加一个名为“Throw”的新动作，并选择“Throw”枚举。
2. 将动画名称字段留空。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FiyNDJKCtVq7N6nyI76jH%2Fimage.png?alt=media&amp;token=37c69fc0-f416-4e63-899c-02de2efcb824" alt="Legacy action configuration with the Throw action selected"><figcaption></figcaption></figure>

### 将对象（岩石）添加到 Convai Interactables Data 脚本中

1. 将任意岩石预制体添加到场景中。
2. 将岩石添加到 Convai Interactable Data 脚本中。

### 向 Convai Interactables Data 脚本添加位置

1. 在场景的地面上添加一个舞台/新位置。
2. 将这个新的位置游戏对象添加到 Convai Interactable Data 中。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fx410GNfL2FwSLk728tpt%2Fimage.png?alt=media&amp;token=6f8aa815-d1e2-45e1-8b82-3400da01656b" alt="Stage location added to the legacy interactable objects list"><figcaption></figcaption></figure>

### 测试复杂动作

1. 点击“播放”以启动场景。
2. 指示 NPC：“捡起岩石，并从舞台上把它扔出去。”
3. 如果所有内容都设置正确，NPC 应该会捡起岩石并从舞台上把它扔出去。

***


---

# 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/adding-actions-to-your-character.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.
