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_beam : MonoBehaviour {
  4. private AudioSource source;
  5. public AudioClip sfxImpBeam;
  6. private float volLowRange = 0.5f; // Volume Low Range
  7. private float volHighRange = 1.0f; // Volume High Range
  8. private float pitchLowRange = 0.75f; // 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 PlayImpBeam(){
  18. if (Time.time > lastHitTime + waitTime) {
  19. lastHitTime = Time.time;
  20. source.pitch = Random.Range (pitchLowRange, pitchHighRange);
  21. source.PlayOneShot (sfxImpBeam, 0.85f);
  22. }
  23. }
  24. void OnCollisionEnter(Collision col){
  25. PlayImpBeam ();
  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. }