Unity3d 如何在UNITY中暂停DontDestroyOnLoad音频?

Unity3d 如何在UNITY中暂停DontDestroyOnLoad音频?,unity3d,Unity3d,我有这个代码在整个场景中播放音频,它工作正常,暂停也工作正常。但当我离开现场并返回时,音频将不再暂停。我应该如何暂停音频 公共音频剪辑声音; 公共音频源 { 得到 { 返回GetComponent(); } } 无效开始() { gameObject.AddComponent(); source.clip=声音; if(source.playOnAwake==true) source.Play(); Button butn=GameObject.Find(“soundButton”).Get

我有这个代码在整个场景中播放音频,它工作正常,暂停也工作正常。但当我离开现场并返回时,音频将不再暂停。我应该如何暂停音频

公共音频剪辑声音;
公共音频源
{ 
得到
{ 
返回GetComponent();
}
}
无效开始()
{
gameObject.AddComponent();
source.clip=声音;
if(source.playOnAwake==true)
source.Play();
Button butn=GameObject.Find(“soundButton”).GetComponent();
但是,onClick.AddListener(PlaySoud);
}
公共空间PlaySoud()
{
if(source.isPlaying)
{
source.Pause();
}
其他的
{
source.Play();
}
}
无效唤醒()
{
GameObject[]obj=GameObject.FindGameObjectsSwithTag(“soundobject”);
如果(对象长度>1)
{
摧毁(这个游戏对象);
}
DontDestroyOnLoad(this.gameObject);
}
  • 你可以找到handy

  • 您可以这样做:

    公共音频源
    { 
    得到
    { 
    return GetComponent-有一个代码段,他们首先调用
    DontDestroyOnLoad
    。它与您的非常相似

  • 您可以在销毁之前尝试调用
    source.Pause()
    ,这可能会提示您的问题

  • 使用

    Debug.Log(“我是”+this.gameobject.name+”,我将被销毁,我的音频是“+(source.isPlaying()?“正在播放:”“不播放”);
    
    在销毁调用之前。然后检查层次结构和控制台,查看保留了什么和删除了什么

  • 如果这不能解决问题,请报告