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

public class VictoryScript : MonoBehaviour
{
    public GameObject TickPrefab;
    public bool Won = false;

    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.transform.tag.Contains("Goal"))
        {
            if (!Won)
            {
                Won = true;
                StartCoroutine(VictoryRoutine(col));
            }
            
            
        }
    }

    IEnumerator VictoryRoutine(Collider2D col)
    {
        Destroy(Spawner.Instance.gameObject);
        Time.timeScale = 0.5f;
        yield return new WaitForSeconds(0.5f);
        GetComponent<LinePainter>().Explode();
        var tickpos = col.transform.GetChild(0).transform.position;
        var tick = Instantiate(TickPrefab);
        tick.transform.position = tickpos;
        
        yield return new WaitForSeconds(0.5f);
        
        Time.timeScale = 1;
        
    }


}
