var speed:int;
var currentSpeed:int;
var sqlClass:sqlClass;

var originalColor:Color;
var changeColor:boolean;

function Start () {
	speed = 30;
	currentSpeed = speed;
	
	var menu:mainMenuController;
	menu = GameObject.FindGameObjectWithTag('menuSetting').GetComponent(mainMenuController);
	
	var player = menu.player;
	
	player.addBalls(this.gameObject);
	
	//Stick the Ball on Start
	var cylinder:cylinderController;
	cylinder = GameObject.FindGameObjectWithTag('cylinder').GetComponent(cylinderController);
	
	originalColor = this.gameObject.renderer.material.color;
	
	yield colorOfBall();
}

function Update () {
}

function OnCollisionExit(otherObject:Collision){
	if(otherObject.transform.tag=='cylinder'){
		this.gameObject.GetComponent(Rigidbody).AddForce(Vector3.up * currentSpeed);
	}
	if(otherObject.transform.tag=='ball'){
		changeColor=true;
	}
}

function colorOfBall(){
	while(true){
		if(changeColor){
			//Change the color
			this.gameObject.renderer.material.color = Color.red;
			yield WaitForSeconds(5);
			changeColor = false;
		}else {
			this.gameObject.renderer.material.color = originalColor;
			yield;
		}
		
	}
}