towers fall from the sky - neat!
This commit is contained in:
parent
d14305d804
commit
362b76ae75
10 changed files with 396 additions and 219 deletions
41
Assets/_Project/Scripts/Combat/TowerLandedSound.cs
Normal file
41
Assets/_Project/Scripts/Combat/TowerLandedSound.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue