samedi 11 avril 2020

How to make 2 if conditions, that one of them must be true before the next condtition

I am using C# in unity and I want to make a condition that key "Z" and "X" must be held down at the same time in order to type a message in debug console (for experiment). I used 2 if and the first key to be held down is Z, if Z is pressed then the code inside it runs and if the X key is pressed too, the message appears. But the problem is even when I first hold down X and then Z, the message pops again!! ( I clear the debug messages each time) How is that possible ?? When I havent held down the Z key, the condition is not met yet and code inside it shouldn't run but it run!! What the problem ?? how to make 2 conditions that one of them must be true before next condition ??

    if (Input.GetKey(KeyCode.Z))
   {
        if (Input.GetKey(KeyCode.X))
        {
             Debug.Log("You just pressed Z then X !!");
        }
   }

Aucun commentaire:

Enregistrer un commentaire