using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;
public class MoneyManager : MonoBehaviour
{
public TowerCollection towerCollection;
[Space(10)]
public GameObject[] ShopButtons;
public TMP_Text[] MoneyTexts;
///
/// Invoked when player selects tower from shop
///
public static event Action OnShopSelected;
private void OnEnable()
{
for (int i = 0; i < ShopButtons.Length; i++)
{
var eventScript = ShopButtons[i].GetComponentInChildren();
eventScript.ButtonIndex = i;
eventScript.OnClick += OnShopButtonClicked;
}
}
private void Start()
{
// Show prices
for (int i = 0; i < towerCollection.Towers.Length; i++)
{
MoneyTexts[i].text = towerCollection.Towers[i].price.ToString();
}
}
private void OnShopButtonClicked(int index)
{
Assert.AreNotEqual(index, -1, "Shop button not init-ed with index");
OnShopSelected?.Invoke(towerCollection.Towers[index]);
}
}