1.首先将音频文件挂载在MainCamera上
2.编写脚本控制跳转场景时音乐继续播放,不自动销毁
public class MusicController : MonoBehaviour {
static MusicController instance = null;
public static MusicController Instance
{
get
{
return instance;
}
}
void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
}
else
{
instance = this;
}
DontDestroyOnLoad(this.gameObject);//使对象目标在加载新场景时不被自动销毁
}
}
3.将脚本挂载在MainCamera上,效果如下
点击开始游戏跳转场景后,音乐继续播放