Files
Shopping_UnityVR/Assets/02_Scripts/UI/BGMHud.cs
2026-05-11 17:27:04 +09:00

44 lines
1.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
public class BGMHud : MonoBehaviour
{
[SerializeField] private GameObject _contentRoot;
[SerializeField] private GameObject _contentPrefab;
private BGMBox currentBgm;
[SerializeField] private BGMClip DefaultBgm;
[SerializeField, Min(0f)] private float _defaultBgmStartDelay = 5f;
public async void Start()
{
if (_defaultBgmStartDelay > 0f)
await Awaitable.WaitForSecondsAsync(_defaultBgmStartDelay);
// 지연 도중에 이미 다른 곡이 재생되었으면 디폴트는 건너뜀
if (currentBgm != null) return;
BGMBox[] BGMBoxs = GetComponentsInChildren<BGMBox>(true);
foreach (BGMBox bgm in BGMBoxs)
{
if(bgm._bgmClip == DefaultBgm)
{
bgm.PlayBGM();
currentBgm = bgm;
}
}
}
public void PlayPickBGM(GameObject buttonObj)
{
if(currentBgm != null)
currentBgm.StopBGM();
BGMBox bgmBox = buttonObj.GetComponentInParent<BGMBox>();
bgmBox.PlayBGM();
currentBgm = bgmBox;
}
}