Built-in Unicode. The question is solved by plugins. Simple and free in asset store = Vibration for Android
There are many methods in it, the method for the duration of the vibration was useful to me.
Vibration(long millis)
This plugin is free, but not without its flaws, in particular, it crashed on some devices when I changed the orientation of the screen.
You can access the built-in Unity plugin using the helper classes https://docs.unity3d.com/ru/530/Manual/PluginsForAndroid.html => Using Java plug-ins with helper classes.
In this case, the code for the vibration will be as follows.
public static class VibratorWrapper { static AndroidJavaObject vibrator = null; static VibratorWrapper() { var unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); var unityPlayerActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity"); vibrator = unityPlayerActivity.Call<AndroidJavaObject>("getSystemService", "vibrator"); } public static void Vibrate(long time) { if (HasVibrator()) vibrator.Call("vibrate", time); }}
Now we run from any class
VibratorWrapper.Vibrate(2000L);
And vibrate for 2 seconds. Note - in the Assets / Plugins / Android folder, you must place the manifest file with the vibration right enabled. For example, like this (file is working).
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" android:installLocation="preferExternal" android:versionCode="1" android:versionName="1.0"> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true"/> <application android:theme="@android:style/Theme.NoTitleBar" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> </intent-filter> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" /> </activity> </application> <uses-permission android:name="android.permission.VIBRATE" />