diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index 47f061f..d4762e9 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -325,8 +325,11 @@ public class PageController : MonoBehaviour { if (_homeBgClip == null) return; if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; } + _bgAudioSource.enabled = true; _bgAudioSource.clip = _homeBgClip; + _bgAudioSource.volume = 0f; _bgAudioSource.Play(); + if (_fadeCoroutine != null) StopCoroutine(_fadeCoroutine); _fadeCoroutine = StartCoroutine(FadeInBg()); Debug.Log("PageController: 播放首页背景音乐"); } @@ -335,7 +338,13 @@ public class PageController : MonoBehaviour { if (_fadeCoroutine != null) { StopCoroutine(_fadeCoroutine); _fadeCoroutine = null; } var allSrcs = gameObject.GetComponents(); - foreach (var s in allSrcs) { if (s != null) s.Stop(); } + foreach (var s in allSrcs) + { + if (s == null) continue; + Debug.Log("PageController: 停止AudioSource clip=" + (s.clip != null ? s.clip.name : "null")); + s.Stop(); + s.enabled = false; + } Debug.Log("PageController: 停止背景音乐 (共" + allSrcs.Length + "个AudioSource)"); } @@ -344,8 +353,11 @@ public class PageController : MonoBehaviour StopBgMusic(); if (_experimentBgClip == null) return; if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; } + _bgAudioSource.enabled = true; _bgAudioSource.clip = _experimentBgClip; + _bgAudioSource.volume = 0f; _bgAudioSource.Play(); + if (_fadeCoroutine != null) StopCoroutine(_fadeCoroutine); _fadeCoroutine = StartCoroutine(FadeInBg()); Debug.Log("PageController: 播放实验背景音乐"); }