Home > other >  Unity c# having trouble getting it too detect when a key is not pressed
Unity c# having trouble getting it too detect when a key is not pressed

Time:03-29

if (Input.GetKeyDown("z") == true)
        {
            moveSpeed = 10;
            
            
        }
        else if (Input.GetKeyDown("z") == false)
        {
            moveSpeed = 5;
        }

that is the code.

When it runs it seems to detect that z is pressed and than set moveSpeed to 10. But than it fails to detect that z is not pressed and resets moveSpeed back to 5.

I have tried a few variations of this code, all seem to have the same result.

CodePudding user response:

you must use Input.GetKeyUp("z")

  • Related