fix: AudioSource设为2D(spatialBlend=0)+FadeInBg加日志
Canvas处于3D空间远端位置(586,330,0),默认3D AudioSource音量衰减到0 spatialBlend=0改为2D全域模式
This commit is contained in:
@@ -53,6 +53,7 @@ public class PageController : MonoBehaviour
|
||||
_bgAudioSource = gameObject.AddComponent<AudioSource>();
|
||||
_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<AudioClip>("Assets/Audio/homeBackgroundMusic.mp3");
|
||||
#endif
|
||||
if (_homeBgClip == null) return; }
|
||||
if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent<AudioSource>(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; }
|
||||
if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent<AudioSource>(); _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<AudioClip>("Assets/Audio/backgroundMusic.mp3");
|
||||
#endif
|
||||
if (_experimentBgClip == null) return; }
|
||||
if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent<AudioSource>(); _bgAudioSource.loop = true; _bgAudioSource.playOnAwake = false; }
|
||||
if (_bgAudioSource == null) { _bgAudioSource = gameObject.AddComponent<AudioSource>(); _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)
|
||||
|
||||
Reference in New Issue
Block a user