using UnityEngine;
using System.Collections;

public class SetupInteractableScript : MonoBehaviour 
{
	public Collider2D[] colliders;
	public Rigidbody2D myRigidbody;

	private Transform myTransform;
	private Transform playerTransform;

	// Use this for initialization
	void OnEnable () 
	{
		playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
		myTransform = transform;

		for (int i = 0; i < colliders.Length; i++)
		{
			colliders[i].isTrigger = true;
		}

		if (myRigidbody != null)
		{
			myRigidbody.isKinematic = true;
		}
	}

	void OnDisable()
	{
		for (int i = 0; i < colliders.Length; i++)
		{
			colliders[i].isTrigger = false;
		}
		
		if (myRigidbody != null)
		{
			myRigidbody.isKinematic = false;
		}
	}
	
	// Update is called once per frame
	void Update () 
	{
		float distance = Vector3.Distance(playerTransform.position, myTransform.position);

		if (distance > Constants.MAX_TARGET_DISTANCE / 2)
		{
			this.enabled = false;
		}
	}
}
