,Doesn't wait for input?
Doesn't seem to waiting for my second "Z" input and I'm not sure why, any help would be appreciated.
{
Debug.Log("Got to line 159");
IsEnemySelectActive = true;
if (Input.GetKeyDown(KeyCode.DownArrow))
{
if (selector < targets.Length)
{
enemyselected++;
}
else
{
enemyselected = 0;
}
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
if (enemyselected > 0)
{
enemyselected--;
}
else
{
enemyselected = targets.Length - 1;
}
}
Debug.Log("got to line 184");
yield return StartCoroutine(waitForKeyPress(KeyCode.Z));
Debug.Log("got to line 187");
IsEnemySelectActive = false;
AttackM();
}
IEnumerator waitForKeyPress(KeyCode key)
{
bool done = false;
while (!done) // essentially a "while true", but with a bool to break out naturally
{
if (Input.GetKeyDown(key))
{
done = true; // breaks the loop
}
yield return null; // wait until next frame, then continue execution from here (loop continues)
}
// now this function returns
},
Can't seem to get this to work? It just runs through the entire IEnumerator without waiting for the second input.
{
Debug.Log("Got to line 159");
IsEnemySelectActive = true;
if (Input.GetKeyDown(KeyCode.DownArrow))
{
if (selector < targets.Length)
{
enemyselected++;
}
else
{
enemyselected = 0;
}
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
if (enemyselected > 0)
{
enemyselected--;
}
else
{
enemyselected = targets.Length - 1;
}
}
Debug.Log("got to line 184");
yield return StartCoroutine(waitForKeyPress(KeyCode.Z));
Debug.Log("got to line 187");
IsEnemySelectActive = false;
AttackM();
}
IEnumerator waitForKeyPress(KeyCode key)
{
bool done = false;
while (!done) // essentially a "while true", but with a bool to break out naturally
{
if (Input.GetKeyDown(key))
{
done = true; // breaks the loop
}
yield return null; // wait until next frame, then continue execution from here (loop continues)
}
// now this function returns
}
Comment
Your answer
Follow this Question
Related Questions
Mega Man Style Camera Movement 0 Answers
Improving script which Spawns enemies up to a required number 0 Answers
HOW TO ADD GRAVITY TO A OBJECT? 2 Answers
NPC walking on air when targeting player 1 Answer
Instantiation help 0 Answers