# 在字母显示时播放声音

要在游戏中实现打字机音效，你可以订阅打字机的“`OnCharacterVisible`” 事件并根据它播放声音。

该事件会传递一个 “char” 作为参数，因此你也可以根据不同字符播放不同的声音。

*附注：该事件也会在空格触发，因此请根据你偏好的字符类型来播放声音。*

***

### 示例包 <a href="#example-package" id="example-package"></a>

作为示例，你可以安装位于 “Extra” 文件夹内的 “TypeWriter Sounds” 包并查看其实现。

![](/files/b51cdece1fcf4544fca530ecf49a5eea5b532894)

<table><thead><tr><th width="221">变量</th><th>说明</th></tr></thead><tbody><tr><td><code>来源</code></td><td>播放声音的主音频源</td></tr><tr><td><code>MinSoundDelay</code></td><td>在播放下一段声音前必须经过的最短时间</td></tr><tr><td><code>中断先前的声音</code></td><td>如果为真，先前的音频将被停止</td></tr><tr><td><code>随机序列</code></td><td>如果为真，下一个要播放的音频剪辑将从 “Sounds” 数组中随机选择。如果为假，声音将按顺序播放</td></tr><tr><td><code>声音</code></td><td>要播放的打字机声音</td></tr></tbody></table>


---

# Agent Instructions: 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:

```
GET https://docs.febucci.com/text-animator-unity/2.x-zh/typewriter/zai-zi-mu-xian-shi-shi-bo-fang-sheng-yin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
