> 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 模型，并为它们添加相同的组件。

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

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

这带来了大量的创意可能性。你可以把蜡烛变成一个杠杆，打开书架后面的密道；从井里发出神秘的声音；把钻石变成可收集物品，点击后会缩小到 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)

**碰撞体**

要让物品可以被点击，重要的是它必须有一个 **碰撞体**。否则你的点击会直接穿过模型，并尝试与后面的物体交互。默认资源包中的 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-he-dong-hua/colliders.md).

{% hint style="info" %}
**💡 提示**：如果你使用了 **网格渲染器** 组件为你的模型赋予了一个原始形状，仅此并不会为它添加碰撞体。你还必须为它指定一个 **网格碰撞体** 组件。
{% endhint %}

**自定义指针事件**

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

* **悬停文本**：更改玩家悬停在物品上时在光标旁看到的提示。这对于说明你的物品是做什么的非常有帮助。
* **最大距离**：玩家与物品交互时可以离多远。
* **显示反馈**：如果未勾选，当玩家将光标移到物品上方时，该物品不会显示悬停提示。
* **按钮**：如果使用 **在输入操作时** 触发操作，你可以将默认的 **主键（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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
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=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
