创造你的世界
用户界面
使用触觉振动
4 分
本指南将向您展示如何在 zepetoscrip 中基于 handheld vibrate 函数实现触觉振动,该函数由 unity 提供。 📘 handheld https //docs unity3d com/scriptreference/handheld html https //docs unity3d com/scriptreference/handheld html 编写脚本 1\) 在 \[项目] 面板中,选择左上角的 \[+] 菜单或选择资产 > 创建 > zepeto > typescript。 2\) 将添加的脚本命名为 hapticvibration,并编写如下示例脚本。 import { zepetoscriptbehaviour } from 'zepeto script'; import { button } from 'unityengine ui'; import { handheld } from 'unityengine'; export default class hapticvibration extends zepetoscriptbehaviour { public vibrationbutton button; start() { this vibrationbutton onclick addlistener(() => { handheld vibrate(); }); } } 3\) 将一个 gameobject 添加到场景中并重命名为 hapticfeedback。添加您创建的 hapticvibration zepetoscript。 在层级窗口中,将按钮 ui 拖放到 zepetoscript 检查器窗口中显示的属性上。 在移动设备上测试 1\) 使用 qr 移动测试运行示例世界。 2\) 当您按下与脚本连接的按钮时,您的设备将会震动。 📘 请参考以下指南。 \[ qr 移动测试 docid\ fuulrf18evdlt jj vvy ] ❗️ 注意 请注意, handheld vibrate 仅在移动环境中有效。