Native vibration plugin for Unity Android(Unity3.x, Unity 4.x Free and Pro).
Your games deserve better vibrations!
Available now on the Asset Store:
Asset Store entry - Market demo
Works with both Basic and Pro.
iPhoneUtils.Vibrate() does vibrate for a long time on iOS and Android too.
Where iOS doesn’t expose a method to do smaller (shorter) vibrations, Android has the ability of vibrate() for a given number of milliseconds and also, play “patterns” of vibrations like morse code, or other combination in patterns with PlayPattern().
Add cool force feedback through the device vibrator in your game or app now !
Tired of having just a half a second vibration ?
Try this and make morse code / rythms / light or heavy rumbles / any kind of vibration you may imagine with VibratePattern () !
Quick Reference C#
For initialization:
Vibrator vibration;
void Start()
{
// Startup vibration Java object
vibration = new Vibrator();
vibration.Init();
}
To invoke it from anywhere:
vibration.Vibrate ( (long) duration ); // make it vibrate for duration milliseconds
vibration.VibratePattern ( (long) pattern[], (int)repeat_index); // play a pattern defined in the pattern[] array with ability of looping it at a given index)
vibration.Cancel(); // stop the current vibration or vibration pattern loop (it stops also an eventual iPhoneUtils.Vibrate() call)
vibration.Dispose(); // Used in OnApplicationQuit stops the vibration and destroy the library class.
Example:
// make it vibrate for 150 milliseconds
vibration.Vibrate ( 150 );
// make it vibrate with pattern myPattern and loop it at position repeatIndex of the pattern (-1 to shot it once)
long[] myPattern = [120,10,100,25,100,25,50,10,50,10,50,10];
int repeatIndex = "5";
vibration.VibratePattern ( mypattern, repeatIndex);
Quick Reference Javascript
For initialization:
static public var vibration : Vibrator;
// note: if you want to use the class right away from any other javascript file and this object will be retained (DontDestroyOnLoad) other wise
// static private var vibration : Vibrator;
function Start()
{
// Startup vibration Java object
vibration = new Vibrator();
vibration.Init();
}
To invoke it from anywhere:
vibration.Vibrate ( 100 ); // make it vibrate for 100 milliseconds
vibration.VibratePattern ( (long) pattern[], (int)repeat_index); // play a pattern defined in the pattern[] array with ability of looping it at a given index)
vibration.Cancel(); // stop the current vibration or vibration pattern loop (it stops also an eventual iPhoneUtils.Vibrate() generic call)
vibration.Dispose(); // Used in OnApplicationQuit stops the vibration and destroy the library class.
Example:
// make it vibrate for 150 milliseconds
vibration.Vibrate ( 150 );
// make it vibrate with pattern myPattern and loop it at position repeatIndex of the pattern
var myPattern : long[] = [120l,10l,100l,25l,100l,25l,50l,10l,50l,10l,50l,10l];
var repeatIndex : int = "5";
vibration.VibratePattern ( myPattern, repeatIndex );(-1 to shot it once)
Enjoy !