Skip to content

Instantly share code, notes, and snippets.

@nndwn
Created April 18, 2024 14:31
Show Gist options
  • Save nndwn/fe529d933000a7999bf66d1d0f66fb31 to your computer and use it in GitHub Desktop.
Save nndwn/fe529d933000a7999bf66d1d0f66fb31 to your computer and use it in GitHub Desktop.
vibrator with duration Unity For Android
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