using UnityEngine;
using System.Collections;

public class VehicleChoice : MonoBehaviour {
	public AircraftController[] vehicles;
	public Transform center;
	public GameObject mobSpawn;
	public GameObject hud;

	float degree_space;
	float distance_from_center=5;
	void Start() {
		GameObject.FindGameObjectWithTag("CenterController")
			.GetComponent<CenterController>().Register("VehicleChoice",this.gameObject);
		gameObject.SetActive(false);

		transform.position = center.position;
		degree_space = 306f/vehicles.Length;
		for(int i=0;i<vehicles.Length;i++) {
			vehicles[i].transform.localPosition = new Vector3(0,0, distance_from_center );
			vehicles[i].transform.RotateAround(transform.position,Vector3.up,degree_space*i);
		}
	}
	bool something_chosen;

	void Update () {
		if ( !something_chosen ) transform.RotateAround(transform.position, Vector3.up,45*Time.deltaTime);
		if ( Input.touchCount > 0 ) {
			Ray r = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
			RaycastHit hit;
			if ( Physics.Raycast(r,out hit, 100) ) {
				Debug.Log("HIT SOMETHING");
			}
		}

	}

	public void MouseUpAsButtonCallBack(AircraftController chosen ) {
		//osen
		chosen.started = true;
		something_chosen = true;
		chosen.transform.parent = null;
		foreach ( AircraftController ac in vehicles ) {
			if ( ac.started == false ) ac.gameObject.SetActive(false);
		}
		mobSpawn.SetActive(true);
		//hud.SetActive(true);
	}
}
