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

public class CrearAntenas : MonoBehaviour {
	public GameObject Antena;
	public GameObject[] AntenasInstanciadas;
	int x;
	int y;
	public float DistanciaMinima;
	public int CantidadDeAntenas;
	private int[] xAntenas;
			int[] yAntenas;
	private int indexUltimaAntena = 0;
	private int nextX,nextY;
	// Use this for initialization
	void Start () {
		xAntenas = new int[CantidadDeAntenas];
		yAntenas = new int[CantidadDeAntenas];
		AntenasInstanciadas = new GameObject[CantidadDeAntenas];
		for (int i = 0; i < CantidadDeAntenas; i++) {
			x = Random.Range (-11, 11);
			y = Random.Range (-4, 7);
			nextX = x;
			nextY = y;
			if(indexUltimaAntena > 0){
				Reacomodar ();
			}
			xAntenas [i] = nextX;
			yAntenas [i] = nextY;
			AntenasInstanciadas[i] = Instantiate (Antena, new Vector3 (nextX, nextY, 0), Quaternion.identity) as GameObject;
			indexUltimaAntena++;
		}

	}

	int generateNextPoints(){
		x = Random.Range (-11, 11);
		y = Random.Range (-4, 7);
		nextX = x;
		nextY = y;
		return nextX;
	}

	void Reacomodar(){
		
		for (int a = 0; a < CantidadDeAntenas; a++) {
			if (AntenasInstanciadas [a] == null) {	
				return;
			}
			if (a != indexUltimaAntena && Vector3.Distance (AntenasInstanciadas [a].transform.position, new Vector3(nextX,nextY,0)) < DistanciaMinima) {
					nextX = Random.Range (-11, 11);
					nextY = Random.Range (-4, 7);
				}
			}
		}
		
}



	




