我刚为我的小测试游戏引入了暂停选项。我有一个背景音频(整个游戏都在播放,即使场景改变时也是如此),所以我决定在游戏暂停时停止音乐。但出现了错误,只要游戏重新加载或更改场景就会弹出以下错误:
感谢您!
"AudioSource 类型的对象已被摧毁。"
能否有人帮忙解决一下?而且... 我认为这是组件,而不是对象!可能两者都有,我不确定。
如何让我的音乐持续播放:
void Awake()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
GameObject.DontDestroyOnLoad(gameObject);
}
}
我的暂停菜单:
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
public AudioSource song;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
song.mute = false;
}
void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
song.mute = true;
}
感谢您!