For a binary case, where something can either go up or down, is it better to use
or with the else
With the first one, even though you would press up, the second if will be checked. In the second case, it only happens is the first returned false. So I would go for the second but don't expect big changes though.
When you don't want to create combo, it is always better to discriminate the inputs. I'll go for the second option (if-else).
Answer by KiraSensei
Nov 12, 2012 at 12:32 PM
In my opinion, since a keyboard can handle 3 keys simultaneously, this will not have the same behavior. The first example will allow your object to go up and down, in the second one this will be go up OR go down, and if both are used, it will only go up.
@ina said either up or down so both won't be used at once. so I would go for second.
@fafase : yes it is my guess too :)
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
12 People are following this question.
Catch Ctrl+Z input in Editor
Play Animation With GetKey
GetKey won't return false?
Input.GetKey() with multiple enum values (C#)
C# Input.GetKey("Tab") Double Tap