From d1430d7b6426cd7693e429183b3f866d27f26583 Mon Sep 17 00:00:00 2001 From: yangbear Date: Wed, 1 Jul 2026 21:50:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20AudioSource=E8=AE=BE=E4=B8=BA2D(spatialB?= =?UTF-8?q?lend=3D0)+FadeInBg=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Canvas处于3D空间远端位置(586,330,0),默认3D AudioSource音量衰减到0 spatialBlend=0改为2D全域模式 --- Assets/Scripts/UI/PageController.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/UI/PageController.cs b/Assets/Scripts/UI/PageController.cs index c161f7c..625ecb9 100644 --- a/Assets/Scripts/UI/PageController.cs +++ b/Assets/Scripts/UI/PageController.cs @@ -53,6 +53,7 @@ public class PageController : MonoBehaviour _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; + _bgAudioSource.spatialBlend = 0f; // 绑定首页按钮 if (_btnStart != null) { _btnStart.onClick.AddListener(OnStartClicked); Debug.Log("PageController: _btnStart 绑定成功"); } @@ -328,7 +329,8 @@ public class PageController : MonoBehaviour _homeBgClip = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Audio/homeBackgroundMusic.mp3"); #endif if (_homeBgClip == null) return; } - if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; } + if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; + _bgAudioSource.spatialBlend = 0f; } _bgAudioSource.enabled = true; _bgAudioSource.clip = _homeBgClip; _bgAudioSource.volume = 0f; @@ -360,7 +362,8 @@ public class PageController : MonoBehaviour _experimentBgClip = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Audio/backgroundMusic.mp3"); #endif if (_experimentBgClip == null) return; } - if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; } + if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; + _bgAudioSource.spatialBlend = 0f; } _bgAudioSource.enabled = true; _bgAudioSource.clip = _experimentBgClip; _bgAudioSource.volume = 0f; @@ -374,6 +377,7 @@ public class PageController : MonoBehaviour { if (_bgAudioSource == null) yield break; float targetVolume = _bgAudioSource.volume > 0.01f ? _bgAudioSource.volume : 0.5f; + Debug.Log("PageController: FadeInBg 目标音量=" + targetVolume + " spatialBlend=" + _bgAudioSource.spatialBlend); _bgAudioSource.volume = 0f; float elapsed = 0f; while (elapsed < duration)