> 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>" %}

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

要向物品添加组件，请点击 **加号图标** ，然后从下拉列表中选择要添加的组件。

![在实体上打开的添加组件菜单会列出组件，并按 3D 内容和交互进行分组，包括动作和触发器。](https://2460066822-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoPnXBby9S6MrsW83Y9qZ%2Fuploads%2Fgit-blob-6a35142910f0343c27340673c61d75ed5f75f05a%2Fadd-component.png?alt=media\&token=a3fb4e60-b24d-4e2a-b9b8-45d7db23aee0)

这提供了大量创意可能性。你可以把蜡烛变成一个打开书架后方秘密通道的杠杆，让井里传出神秘声音，把钻石做成可收集物品，点击后缩小到 0。将这些机制组合起来有无数富有想象力的方法！

## 交互性

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

{% hint style="info" %}
**💡 提示**: 当玩家与物品互动时，你应该提供某种反馈，让这次交互更明确。如果模型没有任何动画，至少可以播放一个声音。在某些情况下，把物品稍微做一个缩放缓动然后恢复到原始大小，也可以作为一种反馈。
{% endhint %}

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

* **指针事件**: 当玩家在将光标对准物品时点击或按下某个键。
* **全局按钮事件** 当玩家在场景中的任何位置按下某个键时。
* **玩家接近**: 当玩家走到物品的位置时。

该 **触发器** 组件可以配置为识别这些类型中的任意一种触发。每次触发发生时，它都可以调用其自身 **操作** 组件中的动作，或调用 **操作** 场景中其他物品的 [智能物件 - 高级](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items-advanced.md).

{% hint style="info" %}
**💡 提示**: 你也可以将这些触发器与 [条件逻辑](/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-89527969929c803b930910be068d3fdc569a36d6%2Fon_click.png?alt=media\&token=8d37a0f4-9ec7-4bd6-8ced-ea2ffdc6c9e8)

**碰撞体**

重要的是，要让物品可以被点击，它必须有一个 **碰撞体**。否则，你的点击会直接穿过模型，并尝试与后面的物体交互。默认素材包中的 3D 模型都应该有碰撞体，但如果你自己创建模型或从其他地方导入，可能会发现它缺少碰撞体。

如果你的模型缺少碰撞体，以下任一种方法都可以修复：

* 添加一个 **网格碰撞体** 组件。这将创建一个带有 [基础形状](/creator/content-creator-zh/chang-jing-sdk7/3d-nei-rong-ji-chu/shape-components.md#primitive-shapes) （立方体、平面、圆柱体、球体）。
* 更改 **碰撞** 部分中的 **GLTF** 组件。 **可见层** 应分配给 **指针**.
* 在 Blender 中编辑 3D 模型，使其包含一个不可见的碰撞体几何体（任何名称以 `_collider`结尾的网格）。参见 [碰撞体](/creator/content-creator-zh/3d-jian-mo-yu-dong-hua/colliders.md).

{% hint style="info" %}
**💡 提示**: 如果你使用了 **网格渲染器** 组件为模型赋予一个原始形状，那么这本身不会为它提供碰撞体。你还必须为它指定一个 **网格碰撞体** 组件。
{% endhint %}

**自定义指针事件**

当物品有一个 **点击时** 或一个 **在输入操作时** 触发动作时，系统使用的默认设置可以被你覆盖。

* **悬停文本**: 更改玩家将光标悬停在物品上时，光标旁边看到的提示。这对于说明你的物品的作用非常有帮助。
* **最大距离**: 玩家在与物品互动时可以离多远。
* **显示反馈**: 如果未勾选，当玩家把光标移到物品上时，物品不会显示悬停提示。
* **Button**: 如果使用 **在输入操作时** 触发动作，你可以将默认的 **主按钮（E）** 重新分配到其他按键。悬停提示会包含一个图标，以说明应使用哪个按键。你可以使用 **副按钮（F）**，或 **动作 3 到 6** （数字键 1 到 4）。

### 全局按钮事件

添加一个 **触发器** 组件，使用 **全局点击时**, **全局主键时** 或 **全局次键时** 触发事件。

* **全局点击时** 会在玩家每次在场景中的任何位置点击鼠标左键时作出反应。
* **全局主键时** 会在玩家每次在场景中的任何位置按下主按钮（E）时作出反应。
* **全局次键时** 会在玩家每次在场景中的任何位置按下副按钮（F）时作出反应。

{% hint style="info" %}
**💡 提示**: 这通常与 [状态和条件](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/states-and-conditions.md)结合起来很有意义，这样只有当玩家在房间里，或满足其他某个条件时，物品才会对按钮事件作出反应。
{% endhint %}

### 玩家位置

添加一个 **触发器** 组件，使用 **玩家进入区域**, **玩家离开区域** 触发事件。

这会在玩家进入或离开一个默认大小为 1x1x1、位于物品中心的区域时作出反应。

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

## 另请参阅

* [智能项目 - 基础](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md)
* [智能物件 - 高级](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items-advanced.md)
* [状态和条件](/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/states-and-conditions.md)
* [与代码结合](/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.
