目标:震动功能

laya商业级3d游戏开发

打开homescenne,增加震动按钮
在这里插入图片描述

新建UIcomponent/Btn/VibrateBtn.ts

export default class VibrateBtn extends Laya.Image {

onAwake() {

    this.skin = Platform.isPlayVibrate() ? 'Textrue/btn_vibrate_on.png' : 'Textrue/btn_vibrate_off.png';

    Utils.addClickEvent(this, this, this.OnClick);
}

OnClick() {

    let isplay = !Platform.isPlayVibrate();
    Platform.setPlayVibrate(isplay);
    this.skin = isplay ? 'Textrue/btn_vibrate_on.png' : 'Textrue/btn_vibrate_off.png';
    console.log('Vibrate', isplay)
}

}

给图片添加runtime脚本

Player.ts
//撞到障碍物失败时手机震动
Fail() {
Platform.vibrateLong()

在这里插入图片描述

Logo

电影级数字人,免显卡端渲染SDK,十行代码即可调用,工业级demo免费开源下载!

更多推荐