using UnityEngine;
using System.Collections;

public class ExitDoor : MonoBehaviour {

    PlayerMovement playerScript;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    protected virtual bool GetPlayerScript()
    {
        GameObject go = GameObject.Find("PlayerMans");
        if (go != null)
        {
            playerScript = go.GetComponent<PlayerMovement>();
        }

        return playerScript != null;
    }

    public void OnTriggerEnter2D(Collider2D other)
    {
        if (playerScript == null && !GetPlayerScript())
            return;

        if (other.gameObject == playerScript.gameObject)
        {
            GameManager gm = GameObject.Find("GameManager").GetComponent<GameManager>();
            playerScript.gameObject.SetActive(false);
            gm.AdvanceToNextFloor();
        }
    }
}
