Advertisement
KorolevDmitry123

Untitled

Apr 15th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 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. public float timer;
  10. void Start()
  11. {
  12. timer = 0.0f;
  13. audioSource = FindObjectOfType<AudioSource>();
  14. audioSource.loop = false;
  15. }
  16. protected AudioClip PlayClip()
  17. {
  18. return clips[Random.Range(0, clips.Length)];
  19. }
  20. void Update()
  21. {
  22. if (playrandom == true)
  23. {
  24. audioSource.clip = PlayClip();
  25. if (pause == false)
  26. {
  27. audioSource.Play();
  28. }
  29. }
  30. else if (playrandom == false)
  31. {
  32.  
  33. }
  34. if (Input.GetKeyDown(KeyCode.F1))
  35. {
  36. if (pause == true)
  37. {
  38. pause = false;
  39. audioSource.Play();
  40. }
  41. else if (pause == false)
  42. {
  43. pause = true;
  44. audioSource.Pause();
  45. }
  46. }
  47. if (Input.GetKeyDown(KeyCode.F2))
  48. {
  49.  
  50. }
  51. if (Input.GetKeyDown(KeyCode.F3))
  52. {
  53.  
  54. }
  55. if (Input.GetKeyDown(KeyCode.F4))
  56. {
  57. playrandom = true;
  58. }
  59. if (playrandom == true)
  60. {
  61. if (timer <= 0.0f || timer >= 0.0f)
  62. {
  63. timer += Time.deltaTime;
  64. }
  65. if (timer >= 0.5f)
  66. {
  67. timer = 0.0f;
  68. playrandom = false;
  69. }
  70. }
  71. }
  72. public void PlayClips()
  73. {
  74. playrandom = false;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement