#pragma strict

var time : float = 0.0;
var point : int = 4;
var Blue : Animator;
Blue = 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;
	Blue.SetBool("Missed", false);
	Blue.SetBool("Pressed", false);
	Blue.SetInteger("Point", 4);
}

function Update () {
var cp = GameObject.Find("Louis").GetComponent(MovementBasic).cp;
	if (time == 0.0)
	{
		Blue.SetBool("Missed", false);
		Blue.SetBool("Pressed", false);
		Blue.SetInteger("Point", 4);
		if (cp!= 0)
		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 - 5, x + 5), y + 1, Random.Range(z - 2, z + 7));
point = Random.Range(0,4);

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

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