You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.0 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class impactSFX_crate : MonoBehaviour {
  4. private AudioSource source;
  5. public AudioClip sfxImpCrate;
  6. private float volLowRange = 0.5f; // Volume Low Range
  7. private float volHighRange = 1.0f; // Volume High Range
  8. private float pitchLowRange = 0.50f; // Pitch Low Range
  9. private float pitchHighRange = 1.0f; // Pitch High Range
  10. private float pitchDefault = 1.0f; // Pitch Default Value
  11. private float lastHitTime = 0.0f;
  12. private float waitTime = 0.5f;
  13. // FUNCTION: Find Audio Source component (attached to Player Avatar Object)
  14. void Awake(){
  15. source = GetComponent<AudioSource> ();
  16. }
  17. void PlayImpCrate(){
  18. if (Time.time > lastHitTime + waitTime) {
  19. lastHitTime = Time.time;
  20. source.pitch = Random.Range (pitchLowRange, pitchHighRange);
  21. source.PlayOneShot (sfxImpCrate, 0.90f);
  22. }
  23. }
  24. void OnCollisionEnter(Collision col){
  25. PlayImpCrate ();
  26. }
  27. // // Use this for initialization
  28. // void Start () {
  29. //
  30. // }
  31. //
  32. // // Update is called once per frame
  33. // void Update () {
  34. //
  35. // }
  36. }