Unity 顺序播放声音

//该脚本绑定到一个空物体上面
using UnityEngine;
using System.Collections;
public class MusicControl : MonoBehaviour
{
    public AudioClip[] music = new AudioClip[3];// 音乐文件
    bool boo = true;// 控制音乐的开关 
    int count = 0;//要播放的声音文件

    void Start()
    { }

    public void PlayerMusic()
    {
        if (!audio.isPlaying)
            if (count < music.Length)
            {
                audio.clip = music[count];
                audio.Play();
                count++;
            }
            else
            {
                count = 0;
            }
    }  
}

//在其他脚本里面调用播放
...
MusicControl mcontrol = musicObject.GetComponent();
mcontrol.PlayerMusic();
...

你可能感兴趣的:(c#,u3d,unity)