using UnityEngine;
using System.Collections;

public class Portal : MonoBehaviour {
	[SerializeField] GameObject otherPortal;
	public bool disabled = false;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	}

	void OnTriggerEnter(Collider other)
	{
		if (other.tag == "Hero" && !disabled)
		{ 
			teleport (other);
		}
	}

	public void activate()
	{
		disabled = false;
	}

	public void deactivate()
	{
		disabled = true;
	}

	public bool isActive()
	{
		return !disabled;
	}
	void teleport (Collider other)
	{
		float x = otherPortal.gameObject.transform.position.x;
		float y = otherPortal.gameObject.transform.position.y;
		float z = otherPortal.gameObject.transform.position.z - otherPortal.gameObject.renderer.bounds.size.z;
		other.transform.position = new Vector3(x,y,z);
		otherPortal.GetComponent<Portal>().deactivate();
		
		deactivate ();
	}
	void OnTriggerExit(Collider other)
	{
		if (other.tag == "Hero")
			activate();
	}
}
