Skip to content

Vibration

Erling Moxnes Kristiansen edited this page Aug 9, 2021 · 2 revisions

Vibration

Static API

Vibration.Vibrate(int duration)

Vibrates for the specified duration(in milliseconds). The parameter duration is not respected on iOS. Only works on Android.


Vibration.Click()

Produces a simple click feedback.


Vibration.DoubleClick()

Produces a double click feedback.


Vibration.HeavyClick()

Produces a heavier and "louder" click feedback.


Vibration.Error()

Produces 4 bursts of feedback. On iOS this uses the OS defined Error feedback pattern.


Vibration.Success()

Produces 2 bursts of feedback. On iOS this uses the OS defined Success feedback pattern.


SelectionFeedbackGenerator

This is used for continuous short feedback when a selection changes.

                    m_feedbackGenerator = new SelectionFeedbackGenerator();
                    m_feedbackGenerator.Prepare(); // optional, but should be done on iOS.

                    m_feedbackGenerator?.SelectionChanged(); // invoke to vibrate

                    m_feedbackGenerator?.Release();

Preferably use SelectionFeedbackGenerator.Prepare() right before vibration should occur to give the iOS haptic feedback generator time to prepare. Not needed for Android.