#pragma strict

var time : float = 0.0;
var point : int = 4;
var Pink : Animator;
Pink = GetComponent(Animator);
var Select : int;
var i:float;
var coord : Transform;
var m : MasterScript;
function Start () {
	m = GameObject.Find("MasterScript").GetComponent(MasterScript);
	coord = GameObject.Find("Nav").transform;
	Pink.SetBool("Missed", false);
	Pink.SetBool("Pressed", false);
	Pink.SetInteger("Point", 4);
}

function Update () {
var cp = GameObject.Find("Louis").GetComponent(MovementBasic).cp;
	if (time == 0.0)
	{
		Pink.SetBool("Missed", false);
		Pink.SetBool("Pressed", false);
		Pink.SetInteger("Point", 4);
		if(cp != 3)
		Spawn();	
	}

}

function Spawn()
{
time = Random.Range(.5, 2.5);
var x = coord.position.x;
var y = coord.position.y;
var z = coord.position.z;

yield WaitForSeconds(time);
transform.position = Vector3(Random.Range(x - 10, x + 10), y + 1, Random.Range(z - 5, z + 15));
point = Random.Range(0,4);

Pink.SetInteger("Point", point);
for (i = 0; i <= 350; i++){
		if(Input.GetKey(KeyCode.DownArrow))
		{
			if(Pink.GetInteger("Point") == 0)
				{
					m.isDebuff();
					Pink.SetBool("Pressed",true);
					Smash();
					break;
				}
			else
				{
					Pink.SetBool("Missed",true);
					break;
				}				
		}
		else if(Input.GetKey(KeyCode.UpArrow))
		{
			if(Pink.GetInteger("Point") == 2)
				{
					m.isDebuff();
					Pink.SetBool("Pressed",true);
					Smash();
					break;
				}
			else
				{
					Pink.SetBool("Missed",true);
					break;
				}
			
			
		}
		else if(Input.GetKey(KeyCode.LeftArrow))
		{
			if(Pink.GetInteger("Point") == 1)
				{
					m.isDebuff();
					Pink.SetBool("Pressed",true);
					Smash();
					break;
				}
			else
				{
					Pink.SetBool("Missed",true);
					break;
				}
			
			
		}
		else if(Input.GetKey(KeyCode.RightArrow))
		{
			if(Pink.GetInteger("Point") == 3)
				{
					m.isDebuff();
					Pink.SetBool("Pressed",true);
					Smash();
					break;
				}
			else
				{
					Pink.SetBool("Missed",true);
					break;
				}
			
			
		}
yield WaitForSeconds(0.01);
}	
	if(i >= 350)
	{
		Pink.SetBool("Missed",true);
	}
	
	time = 0.0;	
}

function Smash()
{
var smash : AudioClip = Resources.Load("SFX/gem_smash", typeof(AudioClip));
	audio.PlayOneShot(smash, 0.5);
}