#pragma strict

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

function Update () {
var cp = GameObject.Find("Louis").GetComponent(MovementBasic).cp;
	if (time == 0.0)
	{
		Red.SetBool("Missed", false);
		Red.SetBool("Pressed", false);
		Red.SetInteger("Point", 4);
		if (cp!= 1)
		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);

Red.SetInteger("Point", point);
for (i = 0; i <= 350; i++){
		if(Input.GetKey(KeyCode.H))
		{
			if(Red.GetInteger("Point") == 0)
				{
					GameObject.Find("MasterScript").GetComponent(MasterScript).isDebuff();
					Red.SetBool("Pressed",true);
					Smash();
					break;
				}
			else
				{
					Red.SetBool("Missed",true);
					break;
				}				
		}
		else if(Input.GetKey(KeyCode.Y))
		{
			if(Red.GetInteger("Point") == 2)
				{
					GameObject.Find("MasterScript").GetComponent(MasterScript).isDebuff();
					Red.SetBool("Pressed",true);
					Smash();
					break;
				}
			else
				{
					Red.SetBool("Missed",true);
					break;
				}
			
			
		}
		else if(Input.GetKey(KeyCode.G))
		{
			if(Red.GetInteger("Point") == 1)
				{
					GameObject.Find("MasterScript").GetComponent(MasterScript).isDebuff();
					Red.SetBool("Pressed",true);
					Smash();
					break;
				}
			else
				{
					Red.SetBool("Missed",true);
					break;
				}
			
			
		}
		else if(Input.GetKey(KeyCode.J))
		{
			if(Red.GetInteger("Point") == 3)
				{
					GameObject.Find("MasterScript").GetComponent(MasterScript).isDebuff();
					Red.SetBool("Pressed",true);
					Smash();
					break;
				}
			else
				{
					Red.SetBool("Missed",true);
					break;
				}
			
			
		}
yield WaitForSeconds(0.01);
}	
	if(i >= 350)
	{
		Red.SetBool("Missed",true);
	}
	
	time = 0.0;	
}

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