diff --git a/Assets/UniAndroidVibration/UniAndroidVibration.cs b/Assets/UniAndroidVibration/UniAndroidVibration.cs index 9338dd1..dc634b3 100644 --- a/Assets/UniAndroidVibration/UniAndroidVibration.cs +++ b/Assets/UniAndroidVibration/UniAndroidVibration.cs @@ -3,12 +3,18 @@ public class UniAndroidVibration { private const string PackageClassPath = "net.sanukin.vibration.UniVibration"; - +#if !UNITY_EDITOR && UNITY_ANDROID + private static AndroidJavaClass _javaClass; +#endif + public static void Vibrate(int milliseconds) { #if !UNITY_EDITOR && UNITY_ANDROID - var javaClass = new AndroidJavaClass(PackageClassPath); - javaClass.CallStatic("vibrate", milliseconds); + if (_javaClass == null) + { + _javaClass = new AndroidJavaClass(PackageClassPath); + } + _javaClass.CallStatic("vibrate", milliseconds); #endif } }