O'Reilly logo

Unity 2D Game Development Cookbook by Claudio Scolastici

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming the character controls

Though we already mentioned a few examples of game controls with Rigidbody and Character Controller, in the following recipe, we will code the actual controls for the game character of our prototype. We couldn't do this before we had working platforms in the prototype! In the following recipe, we will make use of the Rigidbody component and its physics features, plus add in a few simple instructions.

Getting ready

Open up your project. We need a new script for this, so create one as usual in the Scripts folder of your project and name it Runner.

How to do it...

  1. As usual, the script begins with the variable declarations. We need a reference to the Animator attached to the character for the animations, variables for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required