Character Control with Keyboard – Unity3D (C#)


Character Control with Keyboard – Unity3D (C#)

I will show you 2 ways to move your character with keyboard. Create a cube named “Char” and create a script named “Movement”. You can attach this script to Char object but we won’t.  Lets create an object before Start() function:

character is a public game object which means we can reach it from Unity manually. Now, write some if statements in Update() function. This fuction is called in runtime.

Now save it and back to Unity. Attach scriptu2 to camera, select camera and you will see this script in inspector window. Drag Char object to Character bar in script and press play. Is it fast? Don’t worry, just a little change is needed. Back to code and add a float variable:

and replace if statements with:

Current speed is 2.0f but you can change it.

©Coffee Break Codes – Character Control with Keyboard – Unity3D (C#)


Leave a comment

Your email address will not be published. Required fields are marked *

93 thoughts on “Character Control with Keyboard – Unity3D (C#)