using UnityEngine;
using System.Collections;

public class Crane : MonoBehaviour {

    	int phase = 0;
    	bool executing = false;
		Vector3 moveAmount;
		public GameObject LightMaster;

		GameObject executee;

		void Start () {
		}
	
		void Update () {
				if (executing)
						execute ();
		}

		public void enterExecution(GameObject e){
				executee = e;
				executing = true;
				LightMaster.SendMessage ("onSiren");
		}

		void execute(){
				switch(phase){
				case 0:
						transform.position = new Vector3 (executee.transform.position.x, transform.position.y, executee.transform.position.z);
						phase++;
						break;
				case 1:
						if (Mathf.Abs (transform.position.y - executee.transform.position.y) > transform.localScale.y / 2)
								transform.position += new Vector3 (0f, -0.5f, 0f);
						else
								phase++;
						break;
				case 2:
						if (transform.position.y < 50) {
								transform.position += new Vector3 (0f, 0.5f, 0f);
								executee.transform.position += new Vector3 (0f, 0.5f, 0f);
						}
						else
								phase++;
						break;
				case 3:
						transform.position = new Vector3 (0f, 50f, 0f);
						executee.transform.position = new Vector3 (0f,(transform.position.y - transform.localScale.y/2),0f);
								phase++;
						break;
				case 4:
						if (transform.position.y > 8f) {
								transform.position += new Vector3 (0f, -0.5f, 0f);
								executee.transform.position += new Vector3 (0f, -0.5f, 0f);
						}
						else
								phase++;
						break;
				case 5:
						if (executee.transform.position.y > 0f) {
								executee.transform.position += new Vector3 (0f, -0.5f, 0f);
						}
						else
								phase++;
						break;
				case 6:
						if (transform.position.y < 50f) {
								transform.position += new Vector3 (0f, 0.5f, 0f);
						} else {
								LightMaster.SendMessage ("offSiren");
								phase=0;
								executing = false;
						}
						break;

				}
		}
}
