Beginner Scripting: GetButton and GetKey

 



In this weeks Coding Task it looked at the GetKey and GetButton in a game. These help to create actions in a game like to jump or throw an object. It is a confusing lesson to explain as much as it is clear. The Get key specifically names keys for you, using key codes. With the Get button you can specify your own controls. This is the big difference between them. These states work as the return a Boolean of True or False whether the button is being pressed or not. This will in turn result in the action in the game. The action will be True when the button you chose is pressed and this result in the action being complete in the game. It will return to false when the button is not being pressed.

The two different scripts for these are as follows

void Update() { bool down = Input.GetButtonDown("Jump"); bool held = Input.GetButton("Jump"); bool up = Input.GetButtonUp("Jump");

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

Comments

Popular Posts