mirror of
https://github.com/ryzij/Cube-Tower-Defense.git
synced 2026-07-14 10:06:58 +00:00
Теперь звук траты денег воспроизводится только при покупке турели
This commit is contained in:
@@ -4,6 +4,7 @@ public class AudioManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Wallet _wallet;
|
||||
[SerializeField] private GameManager _gameManager;
|
||||
[SerializeField] private TurretsShop _shop;
|
||||
[SerializeField] private AudioSource _levelBackgroundMusic;
|
||||
[SerializeField] private AudioSource _buildBackgroundMusic;
|
||||
[SerializeField] private AudioSource _winMusic;
|
||||
@@ -22,14 +23,16 @@ public class AudioManager : MonoBehaviour
|
||||
_money = _wallet.Money;
|
||||
_state = _gameManager.CurrentState;
|
||||
|
||||
_wallet.OnMoneyChanged += OnMoneyChanged;
|
||||
//_wallet.OnMoneyChanged += OnMoneyChanged;
|
||||
_gameManager.OnStateChanged += OnStateChanged;
|
||||
_shop.OnTurretBought += OnTurretBought;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_wallet.OnMoneyChanged -= OnMoneyChanged;
|
||||
//_wallet.OnMoneyChanged -= OnMoneyChanged;
|
||||
_gameManager.OnStateChanged -= OnStateChanged;
|
||||
_shop.OnTurretBought -= OnTurretBought;
|
||||
}
|
||||
|
||||
public void PlayBlockDestroySound(BlockScript block)
|
||||
@@ -43,17 +46,22 @@ public class AudioManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMoneyChanged(int money)
|
||||
private void OnTurretBought(TurretShopItem _)
|
||||
{
|
||||
var oldMoney = _money;
|
||||
_money = money;
|
||||
|
||||
if (_moneyChangeSound.Length == 0 || oldMoney <= money)
|
||||
return;
|
||||
|
||||
Play(_moneyChangeSound, ref _moneyChangeSoundIndex);
|
||||
}
|
||||
|
||||
//private void OnMoneyChanged(int money)
|
||||
//{
|
||||
// var oldMoney = _money;
|
||||
// _money = money;
|
||||
|
||||
// if (_moneyChangeSound.Length == 0 || oldMoney <= money)
|
||||
// return;
|
||||
|
||||
// Play(_moneyChangeSound, ref _moneyChangeSoundIndex);
|
||||
//}
|
||||
|
||||
private void OnStateChanged(GameManager.GameState newState)
|
||||
{
|
||||
if (newState == _state ||
|
||||
|
||||
@@ -13,6 +13,7 @@ public class TurretsShop : MonoBehaviour
|
||||
[SerializeField] private TurretShopItem[] _turretShopItems;
|
||||
[SerializeField] private UnityEvent<BlockScript> _onBlockSelected;
|
||||
[SerializeField] private UnityEvent _onBlockDeselected;
|
||||
[SerializeField] private UnityEvent<TurretShopItem> _onTurretBought;
|
||||
|
||||
public IReadOnlyCollection<TurretShopItem> TurretShopItems => _turretShopItems;
|
||||
|
||||
@@ -28,6 +29,12 @@ public class TurretsShop : MonoBehaviour
|
||||
remove => _onBlockDeselected.RemoveListener(value);
|
||||
}
|
||||
|
||||
public event UnityAction<TurretShopItem> OnTurretBought
|
||||
{
|
||||
add => _onTurretBought.AddListener(value);
|
||||
remove => _onTurretBought.RemoveListener(value);
|
||||
}
|
||||
|
||||
private BlockScript _selectedBlock;
|
||||
|
||||
private void OnEnable()
|
||||
@@ -77,6 +84,7 @@ public class TurretsShop : MonoBehaviour
|
||||
|
||||
_wallet.TakeMoney(item.Price);
|
||||
Instantiate(item.TurretPrefab, _selectedBlock.transform.position + Vector3.up, Quaternion.identity, _turretsHolder);
|
||||
_onTurretBought?.Invoke(item);
|
||||
DeselectBlock();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user