using UnityEngine;
using System.Collections;

public class Portal : MonoBehaviour {

    public bool active = true;
    public string portalGate = "Portal1";
    public string portalFloor = "";

    public bool status = false;
    public bool hover = false;
    private Vector3 point;
    private Rect t;

    PlayerMovement p;

    void OnCollisionEnter(Collision other)
    {

        if (active) {
            if (other.gameObject.tag == "Player") {
                hover = true;
                p = other.gameObject.GetComponent<PlayerMovement>();
            }
        }

    }

    void OnCollisionExit(Collision other) {
        if (active) {
            if (other.gameObject.tag == "Player") {
                hover = false;
                if (p.teleporting) {
                    p.teleporting = false;
                }
            }
        }

    }

    public void setAction() {

        if (!p.teleporting) {
            p.teleporting = true;
            p.teleport(portalFloor, GameObject.Find(portalGate).transform.position);
        }
    }

    void OnGUI() {
        if (hover) {
            this.point = Camera.main.WorldToScreenPoint(this.gameObject.transform.position);
            this.t = new Rect(point.x, point.y, 300, 300);
            GUI.Label(this.t, "<size=" + ((50)) + ">" + "Teleport" + "</size>");
        }
    }

}
