加载音乐并实现音乐的切换播放
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();
}
}