0
\$\begingroup\$

I'm developing a game with Unity and using C# as the language for the scripts. I want to use the Device Vibration in my Microsoft Phone which is easily available for Windows Phone Development in Visual Studio using the following:

using Windows.Phone.Devices.Notification;

And then calling the following method:

VibrationDevice testVibrationDevice = VibrationDevice.GetDefault();
testVibrationDevice.Vibrate(TimeSpan.FromSeconds(3));

The above works perfectly when I'm building a Windows Phone App from visual Studio. However i totally need to integrate the above functionality in my Unity game.

Any suggestions, workarounds, tips or even hacks would be really helpful. Thanks in advance.

\$\endgroup\$
1
\$\begingroup\$

You should write a plugin to use that method directly in Unity.

Here is how you can create any plugin for Windows Phone in Visual Studio for Unity.

You can write it in both C++ or C#. You will be writing a Windows Phone Class Library that will contain your native methods in it. Then you build some .dllfiles and bring those to Unity an put them in Asset>Plugins>WP directory. Then you can access those methods using namespace.

Be careful when selecting .NET version for RealDLL and FakeDLL.

Tip: In mobile games single vibration is mostly used. If you really don't need the time spanned vibration you can use Handheld.Vibrate().

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .