SoundBowClick.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Sounds for the bow pulling back
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using System.Collections;
  8. namespace Valve.VR.InteractionSystem
  9. {
  10. //-------------------------------------------------------------------------
  11. public class SoundBowClick : MonoBehaviour
  12. {
  13. public AudioClip bowClick;
  14. public AnimationCurve pitchTensionCurve;
  15. public float minPitch;
  16. public float maxPitch;
  17. AudioSource thisAudioSource;
  18. //-------------------------------------------------
  19. void Awake()
  20. {
  21. thisAudioSource = GetComponent<AudioSource>();
  22. }
  23. //-------------------------------------------------
  24. public void PlayBowTensionClicks( float normalizedTension )
  25. {
  26. // Tension is a float between 0 and 1. 1 being max tension and 0 being no tension
  27. float y = pitchTensionCurve.Evaluate( normalizedTension );
  28. thisAudioSource.pitch = ( ( maxPitch - minPitch ) * y ) + minPitch;
  29. thisAudioSource.PlayOneShot( bowClick );
  30. }
  31. }
  32. }