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

public class FallCollider : MonoBehaviour
{
    private PlayerMovement player;
    private TimerScript timeScript;

    private PointAndClick[] myobjects;

    // Start is called before the first frame update
    void Start()
    {
        player = FindObjectOfType<PlayerMovement>();
        timeScript = FindObjectOfType<TimerScript>();
        myobjects = GameObject.FindObjectsOfType<PointAndClick>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "Player")
        {
            player.transform.position = player.startPos;
            player.playerStarted = false;
            player.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
            player.GetComponent<Animator>().SetBool("isWalking", false);

            foreach (PointAndClick myObject in myobjects)
            {
                myObject.transform.position = myObject.startPos;
                myObject.transform.parent = null;
                myObject.GetComponent<SpriteRenderer>().enabled = false;
                myObject.GetComponent<BoxCollider2D>().enabled = false;
                myObject.placeHolder.GetComponent<SpriteRenderer>().enabled = true;

                if (myObject.gameObject.transform.Find("Forward Image"))
                {
                    myObject.gameObject.transform.Find("Forward Image").gameObject.SetActive(false);
                }
            }


            //  SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }
}
