Here is a basic character controller for Unity 2D in C#:
main.cs1279 chars60 linesThis character controller script uses the Rigidbody2D component for movement and the Animator component for animation. The moveSpeed variable controls the character's movement speed, while the jumpForce variable controls the character's jump force.
The Update() function handles movement and animation. The character's velocity is set based on horizontal input from the player using Input.GetAxis("Horizontal"). The character's running animation is controlled by a boolean parameter called isRunning on the Animator component. The OnCollisionEnter2D() and OnCollisionExit2D() functions handle detecting whether the character is grounded or not.
The character can perform a jump by pressing the space bar, but only if the character is currently grounded.
Note that this is a very basic character controller, and you may need to modify this code to fit your specific game requirements.
gistlibby LogSnag