加载音乐并实现音乐的切换播放

public class MusicControl
{
private AudioSource backAudioSource;
private AudioClip BackgroundAudioClip;
private AudioClip RoamAudioClip;

public void Start()
{
BackgroundAudioClip = Resources.Load<AudioClip>("Audio/bcakgroundMusic");
RoamAudioClip = Resources.Load<AudioClip>("Audio/roamMusic");
backAudioSource = Camera.main.GetComponent<AudioSource>();
PlayBackMusic(BackgroundAudioClip);
}

public void PlayBackgroundMusic()
{
PlayBackMusic(BackgroundAudioClip);
}

public void PlayRoamMusic()
{
PlayBackMusic(RoamAudioClip);
}

private void PlayBackMusic(AudioClip _current)
{
backAudioSource.clip = _current;
backAudioSource.Play();
}
}

posted @ 2017-07-25 14:56  U3DEngineer  阅读(251)  评论(0编辑  收藏  举报