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

public class Laser : MonoBehaviour {
	public GameObject cameraLaser;
	public int vectorPicked;
	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 GameObject laser2;
	// Use this for initialization
	void Start () {
		Invoke ("SpawnLaser", 0.5f);
		Invoke ("Kill", 1.1f);
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	void Kill()
	{
		transform.DetachChildren ();
		Destroy (gameObject);
	}

	void SpawnLaser()
	{
		if (transform.parent.name == "Camera") {
			vectorPicked = this.transform.parent.GetComponent<CameraScript> ().vectorPicked;
		} else {
			vectorPicked = this.transform.parent.GetComponent<Laser> ().vectorPicked;
		}
		Instantiate (cameraLaser, transform.position + laserVectors [vectorPicked], Quaternion.identity, transform);
	}
	void OnTriggerEnter2D (Collider2D other)
	{ 

		if (other.gameObject.tag == "Wall")
		{
			Instantiate (laser2, transform.position, Quaternion.identity);
			Destroy (gameObject);
		}
	}

}
