'Unity c# having trouble getting it too detect when a key is not pressed

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.



Solution 1:[1]

you must use Input.GetKeyUp("z")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wondus