Advertisement
Guest User

Untitled

a guest
May 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #pragma strict
  2. @script RequireComponent(AudioSource)
  3.  
  4. public var soundClips:AudioClip[] = new AudioClip[6];
  5.  
  6. private var musicNumber:int = 0;
  7. private var playNextMusic:boolean = true;
  8.  
  9. // Play default sound
  10. function Update ()
  11. {
  12. if(!GetComponent.<AudioSource>().isPlaying) {
  13. if (playNextMusic) PlayTheNextMusic();
  14. }
  15. }
  16.  
  17. function PlayTheNextMusic() {
  18. playNextMusic = false;
  19. GetComponent.<AudioSource>().clip = soundClips[musicNumber];
  20. GetComponent.<AudioSource>().Play();
  21. yield WaitForSeconds (GetComponent.<AudioSource>().clip.length);
  22. playNextMusic = true;
  23. ++musicNumber;
  24. if (musicNumber == soundClips.Length) musicNumber = 0; // I'm not sure if it is Length or length here...
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement