O'Reilly logo

Unity 5.x Cookbook by Chico Queiroz, Matt Smith

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

Player control of a 2D GameObject (and limiting the movement within a rectangle)

While the rest of the recipes in this chapter are demonstrated in 3D projects, basic character movement in 2D, and also limiting the movement to a bounding rectangle, are core skills for many 2D games, and so this first recipe illustrates how to achieve these features for a 2D game.

Since in Chapter 3, Inventory GUI, we already have a basic 2D game, we'll adapt this game to restrict the movement to a bounding rectangle.

Player control of a 2D GameObject (and limiting the movement within a rectangle)

Getting ready

This recipe builds on a simple 2D game called Creating the Simple2DGame_SpaceGirl mini-game from Chapter 3, Inventory GUI. Start with a copy ...

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