death sounds, build sounds, better audio management
This commit is contained in:
parent
a7b2d1854d
commit
9f25844657
26 changed files with 313 additions and 12 deletions
41
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
Normal file
41
Assets/_Project/Scripts/Combat/TowerBuiltSound.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue