Jumping Method

Hello,

I have a simple question about Rick’s approach to the OnJump method.

Here is his approach:

Here is mine:

Why should I check if value is pressed? Doesn’t the method only get called if the key was pressed anyway?

1 Like

Hi,

In many cases, there are multiple ways to make something work in Unity, and Rick cannot show all of them. If your code works, it’s a solution by definition. I think Rick wanted to be on the safe side because we cannot know if OnJump will get called only when a key was pressed. In programming, we often check for certain things before executing a code block even though we are sure that the code will be working. A lot is going on during runtime.

Did this help?


See also:

1 Like

Hey,

I guess it’s saver in case the method gets called anywhere else by accident.

Thank you!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms