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

public class Door : MonoBehaviour
{
    public PressurePlate PressurePlate; 
    public GameObject DoorCollider;
    public Sprite OpenSprite;
    public Sprite ClosedSprite;

    private AudioSource audioSource; 
    private SpriteRenderer spriteRenderer; 

    public void Start()
    {
        this.audioSource = this.GetComponent<AudioSource>();
        this.spriteRenderer = this.GetComponent<SpriteRenderer>(); 
        PressurePlate.OnPressedChanged += OnPressurePlateChanged; 
    }

    private void OnPressurePlateChanged(bool newValue)
    {
        Debug.Log("OnPressurePlateChanged " + newValue); 
        DoorCollider.SetActive(!newValue);
        audioSource.Play();
        spriteRenderer.sprite = newValue ? OpenSprite : ClosedSprite; 
    }

}
