using UnityEngine;
using System.Collections;

public class Doors : MonoBehaviour {
	public float closeY;
	public Vector3 sP;
	public bool open = false;
	private float force = 0.01f;
	void Start () {
		Vector3 p = transform.position;
		sP = new Vector3 (p.x, p.y, p.z);
	}
	void Update () {
		if (open == true) {
			if (closeY > -0.5f) {
				closeY = closeY - 0.01f;
				Vector3 pos = new Vector3 (Random.Range (-force, force), Random.Range (-force, force), Random.Range (-force, force));
				transform.position = new Vector3 (sP.x + pos.x, sP.y + closeY + pos.y, sP.z + pos.z);
			} else {
				transform.position = new Vector3 (sP.x, sP.y + closeY, sP.z);
			}

		}

		if (open == false) {
			if (closeY < 0) {
				closeY = closeY + 0.01f;
				Vector3 pos = new Vector3 (Random.Range (-force, force), Random.Range (-force, force), Random.Range (-force, force));
				transform.position = new Vector3 (sP.x + pos.x, sP.y + closeY + pos.y, sP.z + pos.z);
			} else {
				transform.position = new Vector3 (sP.x, sP.y + closeY, sP.z);
			}
		}
	
	}
}
