#pragma strict

var powerUpObj : GameObject;

var enemySpawnerTarget : GameObject;

var colorProbTrsh = 0.3f;

private var enemies;

var minSpawnTime = 0.2f;
var maxSpawnTime = 0.5f;

var enemyDelta_X = 300;
var enemyDelta_Y = 300;

var minX = -49;
var maxX = 54;
var minY = -9;
var maxY = 51;

var color = 0;

var navicellaRed : Material;
var navicellaYellow : Material;
var navicellaGreen : Material;
var navicellaBlue : Material;

function Start () {

	

	InvokeRepeating("SpawnEnemy", 1, 2.5f);
	//InvokeRepeating("SpawnOlo", 1, 2.0f);
	
	//InvokeRepeating("ChangeColour", 1, 20.0f);
}

function SpawnEnemy() {

	if(enemySpawnerTarget.GetComponent(EnemySpawner).playerTarget.GetComponent(Shoot).playing) {
		var index = 0;
		
		var enemyXpos = Random.Range(minX, maxX);
		var enemyYpos = Random.Range(minY, maxY);
		
		var powerUpObjSpawned = Instantiate(powerUpObj, new Vector3(enemyXpos, enemyYpos, transform.position.z), transform.rotation);
		
		var val : float = Random.Range(0.0f, 1.0f);
		
		if(val <= colorProbTrsh) {
		
			powerUpObjSpawned.renderer.material = GetMaterial(color);
			powerUpObjSpawned.GetComponent(PowerUpScript).color = color;
		
		} else {
		
			var rndCol = Random.Range(0, 4);
		
			powerUpObjSpawned.renderer.material = GetMaterial(rndCol);
			powerUpObjSpawned.GetComponent(PowerUpScript).color = rndCol;
		}
	}
}

function Update () {
	color = enemySpawnerTarget.GetComponent(EnemySpawner).color;
}

function ChangeColour() {

	color ++;
	
	if(color == 4) {
		color = 0;
	}
	
	

}

function GetMaterial(c) : Material {

	switch(c) {
		case 0:
			return navicellaRed;
		case 1:
			return navicellaYellow;
		case 2:
			return navicellaGreen;
		case 3:
			return navicellaBlue;

	}

}