using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyManager : Singleton<EnemyManager>
{
    public delegate void SpawnEnemies(int randomValue);
    public SpawnEnemies spawnEnemies;
    private bool isPlayerAlive = true;

    void Awake() {
        // PlayerManager.I.playerDeath += OnPlayerDeath;
        // PlayerManager.I.playerLive += OnPlayerLive;
    }

    void OnDestroy() {
        if(PlayerManager.HasInstance) {
            // PlayerManager.I.playerDeath -= OnPlayerDeath;
            // PlayerManager.I.playerLive -= OnPlayerLive;
        }
    }

    private void OnPlayerDeath() {
        isPlayerAlive = false;
    }

    private void OnPlayerLive() {
        isPlayerAlive = true;
    }

    private void PromptSpawners() {
        if(spawnEnemies != null) {
            int randomInt = (int) (Random.value * 100);
            spawnEnemies(randomInt);
        }
    }

    void Update() {
        if(isPlayerAlive)
            PromptSpawners();
    }
}
