KorolevDmitry123

Untitled

Apr 15th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. public class MusicPlayer : MonoBehaviour
  4. {
  5. public AudioClip[] clips;
  6. public AudioSource audioSource;
  7. public bool playrandom;
  8. public bool pause;
  9. void Start()
  10. {
  11. audioSource = FindObjectOfType<AudioSource>();
  12. audioSource.loop = false;
  13. }
  14. protected AudioClip PlayClip()
  15. {
  16. return clips[Random.Range(0, clips.Length)];
  17. }
  18. void Update()
  19. {
  20. if (playrandom == true)
  21. {
  22. audioSource.clip = PlayClip();
  23. if (pause == false)
  24. {
  25. audioSource.Play();
  26. }
  27. }
  28. else if (playrandom == false)
  29. {
  30.  
  31. }
  32. if (Input.GetKeyDown(KeyCode.F1))
  33. {
  34. if (pause == true)
  35. {
  36. pause = false;
  37. audioSource.Play();
  38. }
  39. else if (pause == false)
  40. {
  41. pause = true;
  42. audioSource.Pause();
  43. }
  44. }
  45. if (Input.GetKeyDown(KeyCode.F2))
  46. {
  47.  
  48. }
  49. if (Input.GetKeyDown(KeyCode.F3))
  50. {
  51.  
  52. }
  53. if (Input.GetKeyDown(KeyCode.F4))
  54. {
  55. if (playrandom == false)
  56. {
  57. playrandom = true;
  58. }
  59. else if (playrandom == true)
  60. {
  61. playrandom = false;
  62. }
  63. }
  64. }
  65. public void PlayClips()
  66. {
  67. playrandom = false;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment