Guest User

Untitled

a guest
Oct 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GridSFX : MonoBehaviour
  5. {
  6.  
  7. public void Play(Sound sound)
  8. {
  9. GameObject soundObject = new GameObject("Sound Object");
  10. AudioSource audioSource = soundObject.AddComponent<AudioSource>();
  11.  
  12. switch (sound)
  13. {
  14. case Sound.Drop:
  15. audioSource.volume = 0.8f;
  16. audioSource.pitch = 1f;
  17. audioSource.PlayOneShot(dropSound);
  18. Destroy(soundObject, dropSound.length);
  19. break;
  20.  
  21. case Sound.Snap:
  22. audioSource.volume = 0.8f;
  23. audioSource.pitch = 1f + Random.value;
  24. audioSource.PlayOneShot(snapSound);
  25. Destroy(soundObject, snapSound.length);
  26. break;
  27.  
  28. case Sound.Explode:
  29. audioSource.volume = 1f;
  30. audioSource.pitch = 1f + Random.value * 0.05f;
  31. audioSource.PlayOneShot(explodeSound);
  32. Destroy(soundObject, explodeSound.length);
  33. break;
  34. }
  35. }
  36.  
  37. public AudioClip dropSound;
  38. public AudioClip snapSound;
  39. public AudioClip explodeSound;
  40.  
  41. public enum Sound
  42. {
  43. Drop, Snap, Explode
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment