My "if else" condition doesn't works, I can still press all of them same time and the message's showing up too

cud_s02_using_if_else_if__else

#1

image


#2

Hi Beqa,

You won’t be pressing all of them within the same frame though. The Input.GetKeyDown method only returns true during the frame that it is pressed down.

Also, it is better to copy/paste your code into your posts and apply the code formatting characters, rather than add screenshots. They are often quite different to read, especially on mobile devices without a lot of zooming/scrolling. It also prevents those that offer to help you from copy/pasting a part of your code back to you with suggestions/corrections.


See also;


#3

Hey Rob, in the lesson, about between 5:10 - 5:15 Rick says that after adding the “if else” conditions, when we press the keys same time, output is only one, I rewatched it with subtitles on. Mine prints both when I pressing two keys same time.

I’m sorry about the screenshot instead of copy/paste. I didn’t think about someone copy/pasting it(And I’m very used to expressing myself with screenshots, coding society is new to meEmoji ). As im not at my working pc now, Ill copy the code later if you wish.


#4

The code is working perfectly for me. Could you post a video or something similar?


#5

I’ve noticed the same thing. I added in the ‘else’ keywords, and still every time I hit two keys at the same time, they would both show up in the output. I kept at it for a while, though, and I finally did manage to get just one key to show up. Conclusion: It only SEEMS that you hit both keys at the same time, but in reality there’s a tiny difference of at least one frame between them. I’m not going to worry about it for now.


#6

Thank you