SCToggle3DSounds.cs 887 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SC.XR.Unity
  5. {
  6. [RequireComponent(typeof(SCToggleBase))]
  7. public class SCToggle3DSounds : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private AudioClip tapSound = null;
  11. private SCToggleBase toggle;
  12. private AudioSource tapAudioSource = null;
  13. private void Start()
  14. {
  15. if (tapAudioSource == null)
  16. {
  17. tapAudioSource = gameObject.AddComponent<AudioSource>();
  18. }
  19. toggle = GetComponent<SCToggleBase>();
  20. toggle.onValueChanged.AddListener(OnValueChange);
  21. }
  22. private void OnValueChange(bool isOn)
  23. {
  24. if (tapSound != null && tapAudioSource != null)
  25. {
  26. tapAudioSource.PlayOneShot(tapSound);
  27. }
  28. }
  29. }
  30. }