The error should be in line 94 of the code you posted, not the lines you marked. You declared the velocity variable inside your UpdateMovement method in line 79 (of your posted code). So that variable only exists inside this method. So inside your Jump method there is no variable available that is called velocity. Since you seperated out the Y component, you may wanted to use “velocityY” inside Jump?
I only addressed your syntax error. Any logical errors belong to yourself ^^. You should think about what is executed in which order. You have your “jump” detection at the very any of your method. So it’s the last thing that is happening in a frame. So when you press jump you set the Y velocity to the jump force in order to jump up. However look what’s happening the next frame. You have this before all of your movement code:
if (controller.isGrounded)
velocityY = 0.0f;
So of course since you’re still on the ground you just eliminate the velocity you just set at the end of the last frame. So this doesn’t make much sense logically.
Are you looking to learn programming by making a character controller, or do you just want a functioning character controller so you can do other stuff? There’s plenty of those you can start from, such as this one:
That prototype one has run, walk, jump, slide, crouch… it’s crazy-nutty!!
If you want to fix your code:
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.