Question by
daleonard · Jul 07, 2019 at 12:29 PM ·
c#inputcoroutinesienumeratorwhile
Click two buttons at the same time
So I am trying to make something happen when two buttons are pressed at the same time, however using If (Input.GetKey(Key1) && Input.GetKey(key2)
does not seem to work as you need EXACT accuracy to be able for it to work. When trying a while loop everything crashes:
IEnumerator Loopp()
{
bool finished = false;
while (finished == false)
{
if (Input.anyKey)
{
if (Input.GetKey(KeyCode.A) == false && Input.GetKey(KeyCode.B) == false && Input.GetMouseButton(0) == false && Input.anyKey)
{
Debug.Log("fail");
yield break;
}
while (Input.GetKey(KeyCode.A))
{
Debug.Log("First");
if (Input.anyKeyDown)
{
Debug.Log("Second");
if (Input.GetKeyDown(KeyCode.B) == false)
{
Debug.Log("fail2");
}
if (Input.GetKeyDown(KeyCode.B))
{
Debug.Log("succes");
}
}
}
}
else
yield return null;
}
}
This does need to be in an IEnumerator btw (because of other things in the game). Please help! Thanks.
Comment