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

public class RestartGameOnDeath : MonoBehaviour
{
    [SerializeField] float Delay = 3f;
    [SerializeField] string SceneToLoad = "Menu";

    private void Awake()
    {
        Health.OnDied += RestartGame;
    }

    private void OnDestroy()
    {
        Health.OnDied -= RestartGame;
    }

    private void RestartGame(float obj)
    {
        StartCoroutine(Restart());
    }

    private IEnumerator Restart()
    {
        yield return new WaitForSeconds(Delay);
        SceneManager.LoadScene(SceneToLoad);
    }
}
