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

public class Door : MonoBehaviour
{
    public SpriteRenderer openDoorSprite;
    public bool locked;

    void Start(){
        if(!locked){
            openDoorSprite.color = Color.black;
        }
    }

    public void unlock(){
        locked=false;
        openDoorSprite.color = Color.black;
    }


    void Update()
    {

    }

    void OnTriggerEnter2D(Collider2D col){
        Debug.Log(col.gameObject.name + " Entered");
        NetPlayer playerObject = col.GetComponent<NetPlayer>();
        if(!locked&& playerObject!=null){
           if(playerObject.isServer){
               col.GetComponent<PlayerController>().inDoor = true;
           }
        }
    }

    void OnTriggerExit2D(Collider2D col){
        Debug.Log(col.gameObject.name + " Exited");
        NetPlayer playerObject = col.GetComponent<NetPlayer>();
        if(!locked&& playerObject!=null){
           if(playerObject.isServer){
               col.GetComponent<PlayerController>().inDoor = false;
           }
        }        
    }
}
