#pragma strict

var speed = 10.0f;
private var enemies;
var uneffective = false;

var spawnedFrom : GameObject;

function Start () {

	enemies = GameObject.FindGameObjectsWithTag("Nemici");

}

function Update () {

	if(!uneffective) {
		for(var enemy : GameObject in enemies) {
			if(enemy != null) {
			
			var myEnemyBounds = enemy.renderer.bounds;
			
			//myEnemyBounds.size *= 2.0f;
			
				if(this.renderer.bounds.Intersects(enemy.renderer.bounds)) {
					Destroy(enemy);
					Destroy(gameObject);
					Instantiate(enemy.GetComponent(Enemy).explosionParticleSystem, enemy.transform.position, enemy.transform.rotation);
					spawnedFrom.GetComponent(Shoot).score += 300;
					enemies = GameObject.FindGameObjectsWithTag("Nemici");
					break;
				}
			}
		}
	}
	
	transform.Translate(Vector3.right * speed);
	
	if(transform.position.z > 1000) {
		Destroy(gameObject);
	}
	
}