sing UnityEngine;
using System.Collections;
public class music : MonoBehaviour {
//中文字体
public GUISkin ChineseSkin;
//音频文件
public AudioSource[] MyAudio;
//歌曲名称
public string[] SongNames;
//当前歌曲编号
public string[] SongerNames;
//当前歌曲编号
int SongIndex = 0;
//设定是否循环
bool b=true;
bool LoopPlay = true;
// Use this for 初始化
public Texture[] a;
private Texture img;
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
GUI.Label(new Rect(0, 0, Screen.width, Screen.height), a[0]);
GUI.Label(new Rect(0, 0, Screen.width, Screen.height), img);
GUI.skin = ChineseSkin;
if (GUI.Button(new Rect(0,1650,216,270),"开始"))
{
MyAudio[SongIndex].Play();
}
if (GUI.Button(new Rect(216,1650,216,270),"暂停"))
{
MyAudio[SongIndex].Pause();
}
if (GUI.Button(new Rect(432,1650,216,270),"停止"))
{
MyAudio[SongIndex].Stop();
}
if (GUI.Button(new Rect(648,1650,216,270),"上一首"))
{
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
}
//上一曲
if (SongIndex>0)
SongIndex--;
else if(LoopPlay)
SongIndex = MyAudio.Length - 1;
//播放当前音乐
MyAudio[SongIndex].Play();
img=a[SongIndex];
}
if (GUI.Button(new Rect(864,1650, 216,270), "下一首"))
{
//方法一: 停止播放当前音乐
//for (int i = 0; i < MyAudio.Length; i++)
//{
// if (MyAudio[i].isPlaying)
// {
// MyAudio[i].Stop();
// }
//}
//方法二:停止当前播放音乐
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
}
//下一曲
if (SongIndex<MyAudio.Length-1)
SongIndex++;
else if (LoopPlay)
SongIndex = 0;
//播放当前音乐
MyAudio[SongIndex].Play();
img=a[SongIndex];
}
//选择是否进行循环
GUI.contentColor = Color.red;
LoopPlay = GUI.Toggle(new Rect(10, 45, 80, 30), LoopPlay, "循环播放");
}
}
using System.Collections;
public class music : MonoBehaviour {
//中文字体
public GUISkin ChineseSkin;
//音频文件
public AudioSource[] MyAudio;
//歌曲名称
public string[] SongNames;
//当前歌曲编号
public string[] SongerNames;
//当前歌曲编号
int SongIndex = 0;
//设定是否循环
bool b=true;
bool LoopPlay = true;
// Use this for 初始化
public Texture[] a;
private Texture img;
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
GUI.Label(new Rect(0, 0, Screen.width, Screen.height), a[0]);
GUI.Label(new Rect(0, 0, Screen.width, Screen.height), img);
GUI.skin = ChineseSkin;
if (GUI.Button(new Rect(0,1650,216,270),"开始"))
{
MyAudio[SongIndex].Play();
}
if (GUI.Button(new Rect(216,1650,216,270),"暂停"))
{
MyAudio[SongIndex].Pause();
}
if (GUI.Button(new Rect(432,1650,216,270),"停止"))
{
MyAudio[SongIndex].Stop();
}
if (GUI.Button(new Rect(648,1650,216,270),"上一首"))
{
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
}
//上一曲
if (SongIndex>0)
SongIndex--;
else if(LoopPlay)
SongIndex = MyAudio.Length - 1;
//播放当前音乐
MyAudio[SongIndex].Play();
img=a[SongIndex];
}
if (GUI.Button(new Rect(864,1650, 216,270), "下一首"))
{
//方法一: 停止播放当前音乐
//for (int i = 0; i < MyAudio.Length; i++)
//{
// if (MyAudio[i].isPlaying)
// {
// MyAudio[i].Stop();
// }
//}
//方法二:停止当前播放音乐
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
}
//下一曲
if (SongIndex<MyAudio.Length-1)
SongIndex++;
else if (LoopPlay)
SongIndex = 0;
//播放当前音乐
MyAudio[SongIndex].Play();
img=a[SongIndex];
}
//选择是否进行循环
GUI.contentColor = Color.red;
LoopPlay = GUI.Toggle(new Rect(10, 45, 80, 30), LoopPlay, "循环播放");
}
}