Objetivo: función de vibración
desarrollo de juegos 3d comerciales laya
Abra Homescenne y agregue un botón de vibración
Nuevo componente UI / Btn / VibrateBtn.ts
exportar clase predeterminada VibrateBtn extiende 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)
}
}
Agregue un script en tiempo de ejecución a la imagen
Player.ts
// El teléfono vibra cuando no logra chocar contra un obstáculo
Fail () { Platform.vibrateLong ()