Skip to content

Instantly share code, notes, and snippets.

@Dranser
Created August 7, 2016 17:54
Show Gist options
  • Save Dranser/62639ea75d62d2d8363816e783abaadf to your computer and use it in GitHub Desktop.
Save Dranser/62639ea75d62d2d8363816e783abaadf to your computer and use it in GitHub Desktop.
Скрипт позволяющий воспроизводить музыкальные файлы последовательно
using UnityEngine;
using System.Collections;
public class AudioPlayer : MonoBehaviour {
public AudioClip[] Tracks;
public AudioSource Audio_Player;
public int currentTrack = 0;
public bool PlayNow = false;
void Start ()
{
Audio_Player = this.GetComponent<AudioSource> ();
StartCoroutine (NextTrackCheker ());
}
IEnumerator NextTrackCheker()
{
yield return new WaitForSeconds (Audio_Player.clip.length);
PlayNow = true;
}
void Update ()
{
if (currentTrack == Tracks.Length)
{
currentTrack = -1;
}
if (PlayNow)
{
if (currentTrack < Tracks.Length) {
currentTrack = currentTrack + 1;
Audio_Player.clip = Tracks [currentTrack];
Audio_Player.Play ();
PlayNow = false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment