How many of you are struggling trying to find a simple way to add vibration in your Android and iOS game?
Well today your research is over, thanks to BenoitFreslon.
This guy made a native plugin for Unity that makes custom vibrations easy to be implemented with just one single line of code for both Android and iOS.
To install the plugin, copy the content of the “Plugins” folder inside the Unity Plugins folder of your project, and the “Vibration.cs” file in the Assets folder.
-from the Github page:
Vibration
Native plugin for Unity for iOS and Android. Use custom vibrations on mobile.
iOS and Android
- Use
Vibration.Vibrate();
for a classic default ~400ms vibration - Pop vibration: weak boom (For iOS: only available with the haptic engine. iPhone 6s minimum)
Vibration.VibratePop();
- Peek vibration: strong boom (For iOS: only available on iOS with the haptic engine. iPhone 6s minimum)
Vibration.VibratePeek();
- Nope vibration: series of three weak booms (For iOS: only available with the haptic engine. iPhone 6s minimum)
Vibration.VibrateNope();
Android Only
- Custom duration in milliseconds
Vibration.Vibrate(500);
- Pattern
long [] pattern = { 0, 1000, 1000, 1000, 1000 };
Vibration.Vibrate ( pattern, -1 );
- Cancel
Vibration.Cancel();