using UnityEngine;
using System.Collections;

public class DoorMovement : MonoBehaviour
{
    public GameObject[] buttons;
    int activeButtons;
    public bool holdDoor;
    public bool open;

    Vector3 moveOrigin;
    public float doorDistance;
    public float doorSpeed;

	// Use this for initialization
	void Start ()
    {
        open = false;

        moveOrigin = transform.position;
	}
	
	// Update is called once per frame
	void Update ()
    {
        //Are all buttons active?
        activeButtons = 0;
        foreach (GameObject button in buttons)
        {
            if(button.GetComponent<Button>().buttonActive == true)
            {
                activeButtons += 1;
            }
        }
        Debug.Log(activeButtons);
        if (activeButtons >= buttons.Length)
        {
            open = true;
        }
        else
        {
            open = false;
        }

        //Door Opening
        if (open == true)
        {
            transform.position = Vector3.MoveTowards(transform.position, moveOrigin + new Vector3(0, doorDistance, 0), (doorSpeed * Time.deltaTime));
        }
        else if (holdDoor == true)
        {
            Debug.Log("gfgfgsgsdfhgdsah");
            transform.position = Vector3.MoveTowards(transform.position, moveOrigin, (doorSpeed * Time.deltaTime));
        }
    }
}
