// Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
using TD.Audio;
using TD.Gameplay;
using UnityEngine;
namespace TD.Combat
{
///
/// Local-only audio for tower construction completion. Subscribes to
/// and plays a sound on every peer
/// when the tower finishes building.
/// Attach to any tower prefab and assign its clip in the Inspector.
///
[RequireComponent(typeof(TowerInstance))]
public class TowerBuiltSound : MonoBehaviour
{
[SerializeField] private SoundConfig builtSound;
[SerializeField] private float delaySeconds = 0.3f;
private TowerInstance towerInstance;
private void Awake()
{
towerInstance = GetComponent();
}
private void OnEnable()
{
if (towerInstance != null) towerInstance.OnBuiltClient += HandleBuilt;
}
private void OnDisable()
{
if (towerInstance != null) towerInstance.OnBuiltClient -= HandleBuilt;
}
private void HandleBuilt()
{
Invoke(nameof(PlayBuiltSound), delaySeconds);
}
private void PlayBuiltSound()
{
AudioManager.Instance?.Play(builtSound.clip, AudioCategory.UI, builtSound.RandomPitch(), builtSound.volume);
}
}
}