/// <summary> /// 停止播放背景音乐 /// </summary> public void StopBackgroundMusic() { if (BackgroundAudio.isPlaying) { BackgroundAudio.Stop(); } }
/// <summary> /// 播放背景音乐 /// </summary> /// <param name="clip">音乐剪辑</param> /// <param name="isLoop">是否循环</param> /// <param name="speed">播放速度</param> public void PlayBackgroundMusic(AudioClip clip, bool isLoop = true, float speed = 1) { if (BackgroundAudio.isPlaying) { BackgroundAudio.Stop(); } BackgroundAudio.clip = clip; BackgroundAudio.loop = isLoop; BackgroundAudio.pitch = speed; BackgroundAudio.Play(); }