#pragma strict

var speed:int;
var mainController:MainController;
var isDodged:boolean;

function Start ()
{
	isDodged = true;
	mainController = GameObject.FindGameObjectWithTag("MainCamera").GetComponent("MainController");
	
	if (mainController.level == 1)
		speed = 10;
	else if (mainController.level == 2) {
		speed = 12;
		transform.localScale += Vector3(1,0,0);
	}
	else {
		speed = 15;
		transform.localScale += Vector3(2,0,0);
	}
	
	if (transform.position.y > -3.5)
		renderer.material = Resources.Load("Red Material") as Material;
}

function Update ()
{
	transform.Translate(Vector3.left * speed * mainController.level * Time.deltaTime);
}

function OnTriggerEnter(otherObject:Collider)
{
	if (otherObject.tag.Equals("Player"))
		isDodged = false;
}

function OnBecameInvisible()
{
	Destroy(this.gameObject);
	
	if (isDodged)
		mainController.score++;
}