Created
August 7, 2016 17:54
-
-
Save Dranser/62639ea75d62d2d8363816e783abaadf to your computer and use it in GitHub Desktop.
Скрипт позволяющий воспроизводить музыкальные файлы последовательно
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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