About 'Respond To Player Input'!

In this video (objectives)…

  1. Problem solving discussion using Unity docs.
  2. Use Input.GetKeyDown() to recognise when a key is pressed.
  3. Use the KeyCode keyword to determine which key is pressed.
  4. Discuss white space, code blocks and bracketing.
  5. Introduce commenting.

After watching (learning outcomes)… Understand how to recognise player input using Input.GetKeyDown().

(Unique Video Reference: 4_NC_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

1 Like

Hi Rick,
I did the challenge and it appears to equate to your solution, but I still get both key pressed messages.
Any thoughts? I’m on 2018.3, but I doubt that this is the issue

If you can post your code in the udemy Q&A section that corresponds to that lecture we’ll see if we can sort you out.

Hello Rick,

Thanks for the quick reply. Happy Christmas. (I’m in South Africa and Christmas day was 36 degrees and hot!).

After I logged the message, I continued the course, and saw how to copy code from the lecture, which I did, and of course now the problem has been resolved. So a learning opportunity missed, but nevertheless I’m continuing onwards and upwards.

Thanks for the interest,

Great course.

Regards,

Terry

1 Like

Hey Rick,
Quick question, why is better use in the exercise Input.GetKeyDown, instead of Input.GetKeyUp, or Input.GetKey?
Thanks!

1 Like

Good questions. The behaviour we want is that we register a press when the user taps the key. If we listen for GetKeyUp, it will only register once they let go of the key - some people may hold the key down thinking that this is what is needed, and not let the key up for a while. GetKey will continuously fire over and over while someone has it pressed, which in a simple tap could already be many times. So GetKeyDown will be the cleanest way to know if someone has pushed the button.

3 Likes

Thanks :grinning:

1 Like

hello, I am new to coding and tried your challenge to create an input “if statement” at first I tried writing it out like we were showed, then when that did not work I tried to copy and pasting and I still get errors. This is my code, however, the second line is all underlined in red showing there is an error yet it is exactly the same since I copied and pasted. When I go into Unity it states all “compiler errors must be fixed before playing.” How do I fix this issue? {
if (Input.GetKeyDown(KeyCode.UpArrow))
{ Debug.Log(“Up Arrow key was pressed.”); }

    }
}

   
        if (Input.GetKeyDownNewStruct)
        { Debug.Log("Down Arrow key was pressed."); }

Hi Chris,

I’m not sure why you have “GetKeyDownNewStruct” in the code you have shown us.

Visual Studio makes some suggestions for me as I type, but not a lot. It doesn’t seem to make any suggestions related to Unity. Any idea how to change this?

Hello~

I just wanted to stop by on this discussion thread as I am currently watching this lecture on ‘Respond to Player Input’ and wanted to make a small comment about the video. I got to the part where Professor Rick says his and Ben’s mission for us is “World Domination” before quickly switching over to their actual objective :joy: :joy:. It is the little bits of surprising humor like this that make this course so much more enjoyable, while of course being very educational as well! Thank you so much for being the ones to teach this course Professors Rick and Ben!

-Liz :smiley:

I enjoyed the humor as well. I think the pacing of this lecture and the course in general have been great so far. I do like that the course references the docs during lectures, encouraging us to read more deeply into them while following along with the lectures.

You’ve definitely been one of the most engaging instructors I’ve watched over the years (including for programming), so I’m definitely looking forward to seeing more of the course.

1 Like

Glad you’re enjoying the course, I’m happy that you’re getting a laff now and then!

2 Likes

Hey Rick,
I tried running the code to create an input after pressing the Up Arrow key, but it doesn’t work.
Last I checked your video on Visual Studio problems, it was working fine. But still I can’t get the desired output after writing the below code:
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log(“Up Arrow key was pressed.”);
}

Privacy & Terms