diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index 625ecb9..f94aa41 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -50,7 +50,9 @@ public class PageController : MonoBehaviour Debug.Log("=== PageController 初始化开始 ==="); // 背景音乐 AudioSource - _bgAudioSource = gameObject.AddComponent(); + var mainCam = GameObject.Find("Main Camera"); + if (mainCam != null) { _bgAudioSource = mainCam.GetComponent(); if (_bgAudioSource == null) _bgAudioSource = mainCam.AddComponent(); } + else _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; _bgAudioSource.spatialBlend = 0f; @@ -337,7 +339,7 @@ public class PageController : MonoBehaviour _bgAudioSource.Play(); if (_fadeCoroutine != null) StopCoroutine(_fadeCoroutine); _fadeCoroutine = StartCoroutine(FadeInBg()); - Debug.Log("PageController: 播放首页背景音乐"); + Debug.Log("PageController: 播放首页背景音乐, isPlaying=" + _bgAudioSource.isPlaying + " clip=" + (_bgAudioSource.clip!=null?_bgAudioSource.clip.name:"null")); } private void StopBgMusic() @@ -349,7 +351,6 @@ public class PageController : MonoBehaviour 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)"); }