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