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

public class PlaceScript : MonoBehaviour
{
    // Start is called before the first frame update
    public bool directionRight = true;
    private PlayerDialogueManager pdm;

    void Start()
    {
        pdm = GameObject.FindWithTag("Player").GetComponentInChildren<PlayerDialogueManager>();
    }

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

    void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            Debug.Log("player");
            var player = collision.gameObject.GetComponent<MovementManager>();
            if (directionRight == player.directionRight && player.hasShell)
            {
                player.canPlace = true;
                pdm.SetDialogueBox("E");
            }
            else
            {
                collision.gameObject.GetComponent<MovementManager>().canPlace = false;
                pdm.CloseDialogueBox();
            }
        }
    }

    void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            var player = collision.gameObject.GetComponent<MovementManager>();
            collision.gameObject.GetComponent<MovementManager>().canPlace = false;
            pdm.CloseDialogueBox();

        }
    }
}
