#pragma strict

var speed = 10.0f;
var players;

var color;
var powerUpValue = 100;

var whiteDist = 290.0f;

var navicellaWhite : Material;
var originalMaterial : Material;

function Start () {

	players = GameObject.FindGameObjectsWithTag("Player");
	originalMaterial = gameObject.renderer.material;
	
	gameObject.renderer.material = navicellaWhite;
}

function Update () {

	var myBounds = this.renderer.bounds;

	for(var player : GameObject in players) {
		if(player != null) {
			if(myBounds.Intersects(player.renderer.bounds)) {
				Destroy(gameObject);
				
				player.GetComponent(Shoot).powerUp = 1;
				player.GetComponent(Shoot).powerUpColor = color;
				player.GetComponent(Shoot).powerUpValue = powerUpValue;
			}
		}
	}
	
	//enemies = GameObject.FindGameObjectsWithTag("Nemici");
	
	transform.Translate(Vector3.right * speed);
	
	if(transform.position.z < -200) {
		Destroy(gameObject);
	}
	
	if(transform.position.z <= whiteDist) {
		gameObject.renderer.material = originalMaterial;
	}
	if(transform.position.z <= 0) {
		gameObject.renderer.material = navicellaWhite;
	}
	
	
}