Menu Close

GetButton and GetKey

In this video there is nothing to create that will show that I did the video that wouldn’t take too long. The video basically explains the difference between GetButton and GetKey. GetKey takes a direct key to use in the code,  like spacebar, that uses a keycode. For example, KeyCode.Spacebar. While GetButton allows you to name an input, then you select a key for it. Which you can get to by the task bar on the top, edit then project settings then input. Then for both there is 3 functions, GetButton/GetButtonDown/GetButtonUp. GetButton will read true when ever the key is pressed. GetButtonDown will read true for one frame when the button is pressed.  Similarly, GetButtonUp will read true for one frame when the button is released after being pressed. When they are not reading active they stay false.

void Update ()
    {
        bool down = Input.GetKeyDown(KeyCode.Space);
        bool held = Input.GetKey(KeyCode.Space);
        bool up = Input.GetKeyUp(KeyCode.Space);
void Update ()
    {
        bool down = Input.GetKeyDown(KeyCode.Space);
        bool held = Input.GetKey(KeyCode.Space);
        bool up = Input.GetKeyUp(KeyCode.Space);

Leave a Reply

Your email address will not be published. Required fields are marked *