using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Serialization;

public class CoinEntitySpawner : MonoBehaviour
{ 
    [FormerlySerializedAs("Coin Count")] public GameObject coinCount ;
    private TextMeshProUGUI _coinCountTextMeshPro; 
    private EntitySpawner _entitySpawner; 
    void Start()
    {
        _entitySpawner = gameObject.GetComponent<EntitySpawner>();
        _entitySpawner.EntitySpawnEvent += OnCoinSpawn; 
        _coinCountTextMeshPro = coinCount.transform.GetComponent<TextMeshProUGUI>();
    }

    void OnCoinSpawn(Despawn d)
    {
        d.EntityDespawnEvent += OnCoinDespawn; 
    }
    
    void OnCoinDespawn(Despawn d)
    {
        // Incrementing UI coin count
        _coinCountTextMeshPro.text = (int.Parse(_coinCountTextMeshPro.text) + 1).ToString();
    }
    
}
