using UnityEngine;

public class OneWayPlatform : MonoBehaviour
{
	public float HeightBuffer = 1.0f;
	public bool isEnabled { get { return col.enabled; } }
	private BoxCollider2D col;

	void FixedUpdate()
	{
		if (Player.instance == null || col == null)
			return;

		if(col.enabled == false) // must be very aggressive about re-activating the instant player is above platform
		{
			if (Player.instance.position.y > transform.position.y + HeightBuffer)
			{
				col.enabled = true;
			}
		}
		else // collider was already on - we are 20% less agressive about turning it off, to avoid "dropping" at edge cases
		{
			if (Player.instance.position.y < transform.position.y + 0.8f * HeightBuffer)
			{
				col.enabled = false;
			}
		}
	}

	void Start()
    {
		col = GetComponent<BoxCollider2D>();
		col.enabled = true;
    }

}
