This guide will show you how to implement haptic vibration in ZEPETOScrip based on the Handheld.Vibrate
function provided by Unity.
Handheld
Write a script
- In the [Project] panel, select the [+] menu in the upper-left corner or select Assets > Create > ZEPETO > TypeScript.
- Name the added script HapticVibration, and write a sample script as shown below.
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();
});
}
}
- Add a GameObject to the Scene and rename it HapticFeedback. Add the HapticVibration ZEPETOScript you created.
In the Hierachy window, drag & drop the Button UI to the Property shown in the ZEPETOScript Inspector window.
Testing on mobile
- Run the example world with the QR mobile test.
- When you press the button connected to the script, your device will vibrate.
Please refer to the following guide. [QR mobile test]
Caution
Please note that
Handheld.Vibrate
only works in the mobile environment.