Vibration is a great way to give feedback to the player on being attacked. In this tutorial, we will see how you can vibrate an android device in Unity.
Unity has a simple solution for this. Just add the code below to make your phone vibrate. This will work in both Android and IOS.
Handheld.Vibrate();
This works very well but if you want to control the duration of vibration, there is a script written by aVolpe in Github. It’s a custom vibration C# class that you can call to change the vibration duration.
Though the script works on both IOS and Android, the duration is only available for android.
To vibrate your device just call the function of the class.
void Start()
{
Vibration.Vibrate(500)
}
Vibrate permission is required in some cases. You can either make your own manifest to allow vibrations, or Unity creates it automatically with the “Handheld.Vibrate()” line. If your phone doesn’t vibrate with the above code. Then this might be the cause.