using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bridge : MonoBehaviour 
{
	public bool bridge;
	public float distancePlayer; //distance between enemy and player
	public GameObject[] bridgeParts;
	public GameObject[] wall;

	public Transform playerPos;

	// Use this for initialization
	void Start () {
		playerPos = GameObject.Find("Player").GetComponent<Transform>(); //getting player's transform values.

	}
	
	// Update is called once per frame
	void Update () 
	{		
		distancePlayer = Vector3.Distance(playerPos.position,transform.position);

		if(!bridge)
		{
			if(distancePlayer <= 2)
			{
				playerPos.gameObject.GetComponent<Inventory>().targetBridge = this.gameObject;
			}
			else
			{
				if(playerPos.gameObject.GetComponent<Inventory>().targetBridge == this.gameObject)
				{
					playerPos.gameObject.GetComponent<Inventory>().targetBridge = null;
				}
				

			}
		}
		if(bridge)
		{
			for(int i = 0; i < bridgeParts.Length; i++)
			{
				bridgeParts[i].GetComponent<Renderer>().enabled = true;

			}
			for(int i = 0; i < wall.Length; i++)
			{
				wall[i].GetComponent<Collider>().enabled = false;
			}
			this.GetComponent<Bridge>().enabled = false;;

		}
	}


}
