Hi i have some trouble making a script that choose random arrow (left, right, up, down) and instantiate it in the screen and the player has to click on the same arrow as the screen shows.
so it shows one arrow and you click on it and if he clicked on the right arrow than another arrow printed on the screen.
the problem is, the loop is “skipping” the if statements and continue.
so how do i make it “wait” until a player click on one of thos keys…?
the Script:
var arrows:Transform[];
private var i=0;
private var randomArrow=0;
for (i=0; i<10; i++)
{
randomArrow = Random.Range(0,4);
Instantiate (arrows[randomArrow], Vector3(i * 0.09, 0, 0), Quaternion.identity);
if(randomArrow == 0)
{
if(Input.GetKeyDown("left"))
{
Debug.Log("Correct");
i++;
}
if(Input.GetKeyDown("right") || Input.GetKeyDown("up") || Input.GetKeyDown("down"))
{
Debug.Log("Incorrect");
i=10;
}
}
if(randomArrow == 1)
{
if(Input.GetKeyDown("right"))
{
Debug.Log("Correct");
i++;
}
if(Input.GetKeyDown("left") || Input.GetKeyDown("up") || Input.GetKeyDown("down"))
{
Debug.Log("Incorrect");
i=10;
}
}
if(randomArrow == 2)
{
if(Input.GetKeyDown("up"))
{
Debug.Log("Correct");
i++;
}
if(Input.GetKeyDown("right") || Input.GetKeyDown("left") || Input.GetKeyDown("down"))
{
Debug.Log("Incorrect");
i=10;
}
}
if(randomArrow == 3)
{
if(Input.GetKeyDown("down"))
{
Debug.Log("Correct");
i++;
}
if(Input.GetKeyDown("right") || Input.GetKeyDown("up") || Input.GetKeyDown("left"))
{
Debug.Log("Incorrect");
i=10;
}
}
yield WaitForSeconds(3);
Debug.Log ("Failed");
i=10;
}