#pragma strict
var duck: Rigidbody2D;
var bat: Rigidbody2D;
var fish: Rigidbody2D;
var seaHorse: Rigidbody2D;
var numDucks: int;
var thing: Array; 
var posX: float;
var posY: float;
var cController: CrosshairController;
var numOfTargets: int;

function Start () {	
	cController = GameObject.FindGameObjectWithTag("Crosshair").GetComponent(CrosshairController);
	numOfTargets = cController.GetSavedTarget();
	yield GenerateTarget();
}

function Update () {	
	posY = Random.Range(-7,7);
}
 
function GenerateTarget(){

	thing = new Array();
	thing.Push(duck);
	thing.Push(bat);
	thing.Push(fish);
	thing.Push(seaHorse);
		
	
	if(Application.loadedLevel == 2){
		if(numOfTargets == 0)
			numOfTargets = 10;
		for(var i = 0; i < numOfTargets; i++){
			GameObject.Instantiate(thing[0],Vector3(-20,posY,5), Quaternion.identity);
			yield WaitForSeconds(1);
		}
	}else if(Application.loadedLevel == 3){
		if(numOfTargets == 0)
			numOfTargets = 11;
		for(var y = 0; y < numOfTargets; y++){
			GameObject.Instantiate(thing[1],Vector3(-20,posY,5), Quaternion.identity);
			yield WaitForSeconds(1);
		}
	}else if(Application.loadedLevel == 4){
		if(numOfTargets == 0)
			numOfTargets = 12;
		for(var z = 0; z < numOfTargets; z++){
			GameObject.Instantiate(thing[2],Vector3(-20,posY,5), Quaternion.identity);
			yield WaitForSeconds(1);
		}
	}else if(Application.loadedLevel == 5){
		if(numOfTargets == 0)
			numOfTargets = 13;
		for(var w = 0; w < numOfTargets; w++){
			GameObject.Instantiate(thing[3],Vector3(-20,posY,5), Quaternion.identity);
			yield WaitForSeconds(1);
		}
	}
}


