> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/make-any-item-smart.md).

# 让任何物品都变成智能物品

配置任何物品，使其表现得像一个智能物品。

{% embed url="<https://www.youtube.com/watch?v=wnnEU8GCLjc>" %}

智能物件只是带有 **动作** 和/或 **触发器** 组件的普通物件。你可以将这些组件添加到场景中的任何物件上。你也可以导入自己的自定义 3D 模型，并为其添加相同的组件。

要为物件添加组件，请点击 **加号图标** （位于物件名称旁），然后从下拉列表中选择要添加的组件。

![组件添加菜单在一个实体上展开，列出了按“3D 内容”和“交互”分组的组件，其中包括动作和触发器。](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-e735e723bc67fa3ef0cdcb9aff864a9bc8143f34%2Fadd-component.webp?alt=media)

这带来了无穷无尽的创意可能。你可以把蜡烛变成拉杆，打开书架后的密道；从井里播放神秘的声音；还可以把钻石变成可收集物品，点击后缩小至 0。将这些机制组合起来，有许多充满想象力的玩法！

## 交互性

你可以让物品对玩家的不同操作做出反应。

{% hint style="info" %}
**💡 提示**：当玩家与物品交互时，应提供某种反馈，让玩家明确知道交互已发生。如果模型没有动画，可以考虑至少播放一段音效。在某些情况下，可以让物品的缩放略微变化，然后恢复到原始大小，以此作为反馈。
{% endhint %}

添加一个 **Trigger** 组件，用于检测玩家的不同操作：

* **指针事件**：当玩家将光标对准物品并点击，或按下按键时触发。
* **全局按钮事件** 当玩家按下按键时，无论其位于场景的何处。
* **玩家接近**：当玩家走到物件所在位置时。

该 **触发器** 组件可配置为响应上述任何类型的触发事件。每次触发事件发生时，它都可以调用自身 **动作** 组件中的动作，也可以调用场景中其他物件的 **动作** 组件中的动作。参见 [智能物件 - 高级](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items-advanced.md).

{% hint style="info" %}
**💡 提示**：你还可以将这些触发器与 [条件逻辑](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/states-and-conditions.md)结合使用，这样只有在条件为真时才会调用操作，而不是每次触发器触发时都调用。

例如，你可以为一扇门添加 **指针事件** 触发器，让它在被点击时打开，同时加入条件逻辑，使它只有在未上锁时才会打开。
{% endhint %}

### 指针事件

添加 **触发器** 带有该组件的 **单击时** 或 **输入操作时** 触发事件。

* **单击时** 玩家指向该物品时，每次单击鼠标左键都会触发响应。
* **输入操作时** 玩家指向该物品时，每次按下主按钮 (E) 都会触发响应。

![](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-5b8e97937e37b036049a84c9a0eaaa7e0c21fdd0%2Fon_click.webp?alt=media)

**碰撞体**

要让一个物品可以点击，它必须有一个 **碰撞体**。否则，点击会直接穿过模型，并尝试与模型后面的内容交互。默认资产包中的 3D 模型都应该带有碰撞体；但如果你创建自己的模型，或从其他来源获取模型，可能会发现它缺少碰撞体。

如果模型缺少碰撞体，可以通过以下任一方式解决：

* 添加 **网格碰撞体** 组件。它会创建一个具有 [基本形状](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/3d-nei-rong-ji-chu/shape-components.md#primitive-shapes) （立方体、平面、圆柱体、球体）的碰撞体。
* 更改 **碰撞** 部分中的属性，该部分位于 **GLTF** 组件上。 **可见层** 应设为 **指针**.
* 在 Blender 中编辑 3D 模型，添加不可见的碰撞体几何体（名称以 `_collider`结尾的任意网格）。请参阅 [碰撞体](https://docs.decentraland.org/creator/content-creator-zh/3d-jian-mo-yu-dong-hua/colliders.md).

{% hint style="info" %}
**💡 提示**：如果你使用 **网格渲染器** 组件为模型赋予基本形状，这本身并不会为模型添加碰撞体。你还必须为其添加一个 **网格碰撞体** 组件。
{% endhint %}

**自定义指针事件**

当物品具有 **点击时** 或 **输入动作时** 触发动作时，你可以覆盖所使用的默认设置。

* **悬停文本**：更改玩家将鼠标悬停在物品上时，光标旁显示的提示。这有助于说明物品的用途。
* **最大距离**：玩家与物品交互时允许的最远距离。
* **显示反馈**：如果取消勾选，玩家将光标移到物品上时不会显示悬停提示。
* **按钮**：如果使用 **输入动作时** 触发动作，你可以将默认的 **主要（E）** 重新分配给其他按键。悬停提示会显示图标，说明要使用哪个按键。你可以使用 **次要（F）**&#x6216; **动作 3 到 6** （数字键 1 到 4）。

### 全局按钮事件

添加一个 **触发器** 组件，并选择 **全局点击时**, **全局主按键时** 或 **全局副按键时** 触发事件。

* **全局点击时** 玩家在场景中的任何位置点击鼠标左键时，都会触发。
* **全局主按键时** 玩家在场景中的任何位置按下主按键（E）时，都会触发。
* **全局副按键时** 玩家在场景中的任何位置按下副按键（F）时，都会触发。

{% hint style="info" %}
**💡 提示**：通常可以将此功能与 [状态和条件](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/states-and-conditions.md)结合使用，这样只有在玩家位于房间内或满足其他条件时，物品才会响应按键事件。
{% endhint %}

### 玩家位置

添加一个 **触发器** 组件，并选择 **玩家进入区域时**, **玩家离开区域时** 触发事件。

当玩家进入或离开某个区域时，此功能会触发。该区域的默认尺寸为 1x1x1，位于物品的中心。

{% hint style="info" %}
**💡 提示**：通常最好改用 [**触发区域**](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md#trigger-areas) 智能物品，因为在场景编辑器中可以清晰地查看该物品的尺寸。
{% endhint %}

## 另请参阅

* [智能项目 - 基础](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md)
* [智能项目 - 进阶](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items-advanced.md)
* [状态与条件](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/states-and-conditions.md)
* [与代码结合](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/shi-yong-dai-ma-kuo-zhan/overview.md)


---

# 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.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/make-any-item-smart.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.
