using UnityEngine;
using System.Collections;

public class LightMaster : MonoBehaviour {

	public GameObject centerSiren,MainLight,spiningSiren;
	public Vector3[] siren;
	bool PartyNow;
	private ArrayList sirenList = new ArrayList();
	
	void Start () {
		MainLight.light.enabled = true;
		centerSiren.light.enabled = false;
		initSiren (siren);
	}
	
	void Update () {
		if(PartyNow)
			updateSiren();
	}

	void updateSiren(){
		centerSiren.light.range = (Mathf.Sin (7*Time.time)+2f)*9.5f;
		for(int i=0;i<sirenList.Count;i++){
			((GameObject)sirenList[i]).transform.Rotate(new Vector3(0f,10f,0f));
		}

	}

		public void onSiren(){
				PartyNow = true;
				MainLight.light.enabled = false;
				centerSiren.light.enabled = true;
				for (int i = 0; i < sirenList.Count; i++) {
						((GameObject)sirenList [i]).transform.FindChild ("SpotA").gameObject.light.enabled = true;
						((GameObject)sirenList [i]).transform.FindChild ("SpotB").gameObject.light.enabled = true;
				}
		}

		public void offSiren(){
				PartyNow = false;
				MainLight.light.enabled = true;
				centerSiren.light.enabled = false;
				for (int i = 0; i < sirenList.Count; i++) {
						((GameObject)sirenList [i]).transform.FindChild ("SpotA").gameObject.light.enabled = false;
						((GameObject)sirenList [i]).transform.FindChild ("SpotB").gameObject.light.enabled = false;
				}
		}

		public void initSiren(Vector3[] sirenPositions){
				for(int i=0;i<sirenPositions.Length;i++){
						sirenList.Add (Instantiate(spiningSiren,sirenPositions[i],Quaternion.identity));
				}
		}
}
