Laya商业级3d实战_015震动功能

目标:震动功能

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()

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/koljy111/article/details/108020359