using UnityEngine;
using ;
//中文字体
public GUISkin ChineseSkin;
//音频文件
public AudioSource[] MyAudio;
//歌曲名称
public string[] SongNames;
//当前歌曲编号
public string[] SongerNames;
//当前歌曲编号
int SongIndex = 0;
//设定是否循环
bool LoopPlay = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
= ChineseSkin;
if ((new Rect(10,10,50,30),"开始"))
{
MyAudio[SongIndex].Play();
}
if ((new Rect(70,10,50,30),"暂停"))
{
MyAudio[SongIndex].Pause();
}
if ((new Rect(130,10,50,30),"停止"))
{
MyAudio[SongIndex].Stop();
}
if ((new Rect(190,10,60,30),"上一首"))
{
///方法一: 停止播放当前音乐
//for (int i = 0; i < ; i++)
//{
// if (MyAudio[i].isPlaying)
// {
// MyAudio[i].Stop();
// }
//}
//方法二:停止当前播放音乐
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
}
//上一曲
if (SongIndex>0)
SongIndex--;
else if(LoopPlay)
SongIndex = - 1;
//播放当前音乐
MyAudio[SongIndex].Play();
}
if ((new Rect(260, 10, 60, 30), "下一首"))
{
//方法一: 停止播放当前音乐
//for (int i = 0; i < ; i++)
//{
// if (MyAudio[i].isPlaying)
// {
// MyAudio[i].Stop();
// }
//}
//方法二:停止当前播放音乐
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
}
//下一曲
if (SongIndex<-1)
SongIndex++;
else if (LoopPlay)
SongIndex = 0;
//播放当前音乐
MyAudio[SongIndex].Play();
}
//选择是否进行循环
= ;
LoopPlay = (new Rect(10, 45, 80, 30), LoopPlay, "循环播放");
//显示当前歌手和歌曲名称
(new Rect(10, 80, , 30), "当前歌曲名称:"+SongNames[SongIndex]);
(new Rect(10, 115, , 30), "歌手姓名"+SongerNames[SongIndex]);
= ;
}
}