fix: StopBgMusic停止Canvas上所有AudioSource,消除潜藏旧组件

之前的PlayHomeBg/PlayExperimentBg每次run可能残留重复AddComponent
现在GetComponents<AudioSource>()遍历停止全部,不依赖单引用
This commit is contained in:
yangbear
2026-07-01 21:32:22 +08:00
parent 798393edee
commit c9eda6a9f7
+3 -5
View File
@@ -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()