fix: StopBgMusic停止Canvas上所有AudioSource,消除潜藏旧组件
之前的PlayHomeBg/PlayExperimentBg每次run可能残留重复AddComponent 现在GetComponents<AudioSource>()遍历停止全部,不依赖单引用
This commit is contained in:
@@ -335,11 +335,9 @@ public class PageController : MonoBehaviour
|
||||
private void StopBgMusic()
|
||||
{
|
||||
if (_fadeCoroutine != null) { StopCoroutine(_fadeCoroutine); _fadeCoroutine = null; }
|
||||
if (_bgAudioSource != null)
|
||||
{
|
||||
_bgAudioSource.Stop();
|
||||
Debug.Log("PageController: 停止背景音乐");
|
||||
}
|
||||
var allSrcs = gameObject.GetComponents<AudioSource>();
|
||||
foreach (var s in allSrcs) { if (s != null) s.Stop(); }
|
||||
Debug.Log("PageController: 停止背景音乐 (共" + allSrcs.Length + "个AudioSource)");
|
||||
}
|
||||
|
||||
private void PlayExperimentBg()
|
||||
|
||||
Reference in New Issue
Block a user