using UnityEngine;
using System.Collections;

public class DoorButton : MonoBehaviour {

    public Sprite openSprite;
    public Sprite closeSprite;
    SpriteRenderer spriteRenderer;
    public GameObject door;

    public AudioSource buttonAudio;
    public AudioSource doorAudio;

    public bool isOpen;

	// Use this for initialization
	void Start () {
        spriteRenderer = GetComponent<SpriteRenderer>();
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void OnTriggerEnter2D(Collider2D other){
        if (other.gameObject.CompareTag("Player"))
        {
            buttonAudio.Play();
            if (isOpen)
            {
                isOpen = false;
                spriteRenderer.sprite = closeSprite;
                door.SetActive(true);
            }
            else
            {
                doorAudio.Play();
                isOpen = true;
                spriteRenderer.sprite = openSprite;
                door.SetActive(false);
            }
        }
    }
}
