From c9eda6a9f778f51a19ab2f838310b076d5cc674f Mon Sep 17 00:00:00 2001 From: yangbear Date: Wed, 1 Jul 2026 21:32:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20StopBgMusic=E5=81=9C=E6=AD=A2Canvas?= =?UTF-8?q?=E4=B8=8A=E6=89=80=E6=9C=89AudioSource=EF=BC=8C=E6=B6=88?= =?UTF-8?q?=E9=99=A4=E6=BD=9C=E8=97=8F=E6=97=A7=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前的PlayHomeBg/PlayExperimentBg每次run可能残留重复AddComponent 现在GetComponents()遍历停止全部,不依赖单引用 --- Assets/Scripts/UI/PageController.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index f0e4ace..bffc91a 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -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(); + foreach (var s in allSrcs) { if (s != null) s.Stop(); } + Debug.Log("PageController: 停止背景音乐 (共" + allSrcs.Length + "个AudioSource)"); } private void PlayExperimentBg()