What is Unity GetKeyDown - GetKey - GetKeyUp? And What Are Their Differences?
Hello friends, in this post I will explain what the keyboard Inputs (Entries) with GetKey - GetKeyDown - GetKeyUp are used for in Unity, and their differences. Let's get started with the article.
What are GetKey - GetKeyDown - GetKeyUp?
Yes, friends, before talking about their differences, let's see what these are.With these commands, we can detect the buttons pressed by the user from the mouse and accordingly use if statements to operate basic game functions such as character movement, opening the inventory, and many more.
GetKey
It is the command used to perform continuous actions for as long as the key is held down, and at the same time, it runs one last time after the finger is lifted from the key.GetKeyDown
It is the command that works when the key is pressed and does not work when the finger is lifted.GetKeyUp
It is the command that only works when the finger is lifted off the key.What Are the Differences?
Actually, if you have read the "What is it?" part, you have probably already noticed the differences, but let's address them anyway.
GetKey
The difference from the others is that it works in all situations: when the key is pressed, when you hold it down, and when you release your finger, it works like GetKeyUp as well.
In other words, GetKey is the version that works when held down in addition to the other two.
In general, it is used where the character needs to walk or move continuously while the finger is held down.
GetKeyDown
Its difference from the others is that it works at the first moment the finger is pressed and then stops working. So when the user holds it down or when they release the finger, it does not work; it only works once when pressed, and then stops. If you want to execute the same command again, instead of holding it down, you need to lift and press the button once more.
It is generally used to open inventory, jump, and similar cases.
GetKeyUp
The difference from the others is that it works when the finger is lifted. It works once when the finger is lifted from the key and then stops.
In general, because I have never used it until now, I can't say where it would be used.


Yorum Gönder