Created
April 18, 2024 14:31
-
-
Save nndwn/fe529d933000a7999bf66d1d0f66fb31 to your computer and use it in GitHub Desktop.
vibrator with duration Unity For Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public static class Vibre | |
{ | |
#if UNITY_ANDROID | |
public static void Vibrator(long milliseconds ) | |
{ | |
if (Application.isEditor ) Handheld.Vibrate(); | |
if (Application.platform == RuntimePlatform.Android) | |
{ | |
var localeClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | |
var currentActivity = localeClass.GetStatic<AndroidJavaObject>("currentActivity"); | |
var vibra = currentActivity.Call<AndroidJavaObject>("getSystemService", "vibrator"); | |
if (!PlayerPrefs.HasKey(Pref.Vibration)) | |
vibra.Call("vibrate", milliseconds); | |
} | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment