Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
SourceIntensitySlider.cs
Go to the documentation of this file.
1/* ​
2* Copyright (c) 2023 Go Touch VR SAS. All rights reserved. ​
3* ​
4*/
5
7using UnityEngine;
8using UnityEngine.UI; // Required for UI components
9
11{
12 [RequireComponent(typeof(Slider))]
13 public class SourceIntensitySlider : MonoBehaviour
14 {
16 private Slider slider;
17
18 private void Awake()
19 {
20 slider = GetComponent<Slider>();
21 if (hapticSources[0] != null)
22 {
23 slider.value = hapticSources[0].SourceIntensity;
24 slider.onValueChanged.AddListener(HandleSliderValueChanged);
25 }
26 else
27 {
28 Debug.Log("No HapticSource component found in the HapticSources array.");
29 }
30 }
31
32 public void HandleSliderValueChanged(float value)
33 {
34 // Update the source intensity for all Haptic Sources when the slider's value changes
35 foreach (HapticSource hapticSource in hapticSources)
36 {
37 if (hapticSource != null)
38 {
39 hapticSource.SourceIntensity = value;
40 hapticSource.ApplySourceIntensity();
41 }
42 }
43 }
44 }
45}
void ApplySourceIntensity()
Call this method to apply the source intensity.