
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraScript : MonoBehaviour {

	public GameObject cameraLaser;
	public GameObject cameraVerticalLaser;
	public Vector3 firstVector;
	public Vector3[] laserVectors = new [] {new Vector3(-1,0,0), new Vector3(0,1,0), new Vector3(1,0,0), new Vector3(0,-1,0)};
	public int vectorPicked;
	public Animator anim;

	// Use this for initialization
	void Start () {
		anim = GetComponent<Animator> ();
		InvokeRepeating ("SpawnLaser", 0, 0.5f);
	}
	
	// Update is called once per frame
	void Update () {

	}
	void SpawnLaser()
	{
		if (vectorPicked % 2 == 0) {
		
			Instantiate (cameraLaser, transform.position + firstVector, Quaternion.identity, transform);
		} 
		else 
		{
			Instantiate (cameraVerticalLaser, transform.position + firstVector, Quaternion.identity,transform);
		}
	}
	public void TurnCamera()
	{
		transform.DetachChildren ();
		Debug.Log ("todo ok");
		int ogvector = vectorPicked;
		if (ogvector == 0) {
			firstVector = new Vector3 (0f, 0.5f, 0f);
			vectorPicked++;
			transform.Rotate (0, 0, -90);
		} else if (ogvector == 1) {
			firstVector = new Vector3 (0.5f, 0f, 0f);
			vectorPicked++;
			transform.Rotate (0, 0, -90);
		} else if (ogvector == 2) {
			firstVector = new Vector3 (0f, -0.5f, 0f);
			vectorPicked++;
			transform.Rotate (0, 0, -90);
		} else if (ogvector == 3) {
			firstVector = new Vector3 (-0.5f, 0f, 0f);
			vectorPicked = 0;
			transform.Rotate (0, 0, -90);
		}
		Invoke ("TurnCameraBack", 5);
	}
		public void TurnCameraBack()
		{
		transform.DetachChildren ();
		int ogvector = vectorPicked;
		if (ogvector == 0) {
			firstVector = new Vector3 (0f, -0.5f, 0f);
			vectorPicked = 3;
			transform.Rotate (0, 0, 90);
		} else if (ogvector == 1) {
			firstVector = new Vector3 (-0.5f, 0f, 0f);
			vectorPicked--;
			transform.Rotate (0, 0, 90);
		} else if (ogvector == 2) {
			firstVector = new Vector3 (0f, 0.5f, 0f);
			vectorPicked--;
			transform.Rotate (0, 0, 90);
		} else if (ogvector == 3) {
			firstVector = new Vector3 (0.5f, 0f, 0f);
			vectorPicked--;
			transform.Rotate (0, 0, 90);
		}
		}
	
	public void ExplodeCamera()
	{
		CancelInvoke ();
		anim.Play("Camera Explosion Animation");

	}
}
