首先创建两个场景: One,Two

再创建一个空游戏对象: GameObject,并添加AudioSource组件,把要播放的音乐拖放进去

给GameObject添加脚本AlwayAudio,代码如下:

1 using UnityEngine;
2 using System.Collections;
3 
4 public class AlwayAudio : MonoBehaviour {
5 
6     void Start () {
7         DontDestroyOnLoad(this.gameObject);
8     }
9 }
保持GameObject不被销毁的代码

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-07-24
  • 2021-06-06
  • 2021-10-13
  • 2021-12-28
猜你喜欢
  • 2021-06-05
  • 2022-02-17
  • 2021-08-07
  • 2021-09-17
  • 2022-12-23
  • 2021-11-01
相关资源
相似解决方案