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

public class ChangeScene : MonoBehaviour
{
    public ParticleSystem particulaPrefab;
    public float tiempoDeEspera = 2f;
    public string nombreEscena;

    private bool activado = false;

    private void OnTriggerEnter(Collider other)
    {
        if (activado) return;

        if (other.CompareTag("Player"))
        {
            activado = true;
            StartCoroutine(Cambiar());
        }
    }

    IEnumerator Cambiar()
    {
        if (particulaPrefab != null)
        {
           
            ParticleSystem p = Instantiate(
                particulaPrefab,
                transform.position,
                transform.rotation
            );

            p.Play();

            
            Destroy(p.gameObject, p.main.duration + p.main.startLifetime.constantMax);
        }

        yield return new WaitForSeconds(tiempoDeEspera);

        SceneManager.LoadScene(nombreEscena);
    }
}