44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
// Assets/_Project/Scripts/Combat/TeslaTowerFireSound.cs
|
|
using TD.Audio;
|
|
using UnityEngine;
|
|
|
|
namespace TD.Combat
|
|
{
|
|
/// <summary>
|
|
/// Local-only audio for the Tesla Coil tower. Subscribes to
|
|
/// <see cref="TowerCombat.OnAreaFired"/> and plays a one-shot fire sound
|
|
/// on every peer each time the coil discharges.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Pure client-side — nothing here is networked. Add additional
|
|
/// <see cref="AudioClip"/> fields and <see cref="AudioSource"/> calls here
|
|
/// as the Tesla Coil gains more audio (idle hum, charge-up, etc.).
|
|
/// </remarks>
|
|
[RequireComponent(typeof(TowerCombat))]
|
|
public class TeslaTowerFireSound : MonoBehaviour
|
|
{
|
|
[SerializeField] private SoundConfig fireSound;
|
|
|
|
private TowerCombat combat;
|
|
|
|
private void Awake()
|
|
{
|
|
combat = GetComponent<TowerCombat>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (combat != null) combat.OnAreaFired += HandleAreaFired;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (combat != null) combat.OnAreaFired -= HandleAreaFired;
|
|
}
|
|
|
|
private void HandleAreaFired(Vector3[] positions)
|
|
{
|
|
AudioManager.Instance?.Play(fireSound.clip, AudioCategory.Combat, fireSound.RandomPitch(), fireSound.volume);
|
|
}
|
|
}
|
|
}
|