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