- Home /
How to control vibration duration of Handheld.Vibrate()?
I don't really need a 1 second vibration for every touch. Is there any way of controlling the duration here?
This would be a very useful thing to make configurable
Answer by SuperJaques · Apr 08, 2016 at 11:26 AM
if (Application.platform != RuntimePlatform.Android) return;
AndroidJavaClass unity= new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject ca = unity.GetStatic("currentActivity"); AndroidJavaClass vibratorClass = new AndroidJavaClass("android.os.Vibrator"); AndroidJavaObject vibratorService = ca.Call("getSystemService",ca.GetStatic("VIBRATOR_SERVICE"));
vibratorService.Call("vibrate", (long)timeInMilliseconds);
unity.Dispose();
ca.Dispose();
vibratorClass.Dispose();
vibratorService.Dispose();
remember to add permission for vibration to manifest and check ur device vibrates.
youre welcome.
Answer by Anisoropos · Mar 06, 2016 at 11:39 PM
I've been searching for the past month. All I found was this simple, cheap and functioning plugin for Android which lets you vibrate for a specific duration.
The bad part is that Handheld.Vibrate doesn't seem to be working at all for Windows Phone.