#pragma strict
var pineappleS:GameObject;
var splashOrange:GameObject;
var splashBlue:GameObject;
var x:float;
var y:float;
var speed:int;
var rand:int;
var playerController:MouseController;
var throwSound:AudioClip;

function slice(){	
	//Instantiate a Sliced Pineapple
	Instantiate(pineappleS, transform.position, transform.rotation);
	
	//Random a number and if it is 1, increment the Bonus Score by 10
	rand = Random.Range(1,10);
	if(rand == 1){
		//Increment the Score by 10 (Bonus aKa Critical +10 in Fruit Ninja)
		playerController.incrementBonusScore();
		
		//Display a Blue Splash on the Background
		Instantiate(splashBlue, Vector3(x,y,10), Quaternion.identity);
	}else{
		//Increment the Score by 1
		playerController.incrementScore();
		
		//Display an Orange Splash in the Background
		Instantiate(splashOrange, Vector3(x,y,10), Quaternion.identity);
	}
	//Destroy the Pineapple Object
	Destroy(this.gameObject);
}

function Start () {
	//Play Throw Sound
	audio.PlayOneShot(throwSound);

	//Call the MouseController Component
	playerController = GameObject.FindGameObjectWithTag("Player").GetComponent(MouseController);
	
	speed = 200;
}

function Update () {
	x = transform.position.x -2;
	y = transform.position.y;
	//transform.Rotate(Vector3.up*speed*Time.deltaTime);
	//transform.Rotate(Vector3.right*speed*Time.deltaTime);
	//transform.Translate(Vector3.left*4*Time.deltaTime);
}

function OnBecameInvisible(){
	Destroy(this.gameObject);
}

function OnTriggerEnter(hitObject:Collider){
	//If the Pineapple is hit by the Player, Slice it
	if(hitObject.gameObject.tag == "Player"){
		slice();
	}
}