Book Image

Unity 5.x 2D Game Development Blueprints

By : Francesco Sapio
Book Image

Unity 5.x 2D Game Development Blueprints

By: Francesco Sapio

Overview of this book

Flexible, powerful, and full of rich features, Unity 5 is the engine of choice for AAA 2D and 3D game development. With comprehensive support for over 20 different platforms, Unity boasts a host of great new functions for making 2D games. Learn how to leverage these new options into awesome 2D games by building three complete game projects with the Unity game tutorials in this hands-on book. Get started with a quick overview of the principle concepts and techniques needed for making 2D games with Unity, then dive straight in to practical development. Build your own version of Super Mario Brothers as you learn how to animate sprites, work with physics, and construct brilliant UIs in order to create a platformer game. Go on a quest to create a RPG game discovering NPC design, event triggers, and AI programming. Finally, put your skills to the test against a real challenge - designing and constructing a complex strategy game that will draw on and develop all your previously learned skills.
Table of Contents (15 chapters)
Unity 5.x 2D Game Development Blueprints
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface

Placing the towers


When the player buys a tower, they have the possibility to place it where they want. In order to include this feature inside our game, we need to make some changes to our towers.

Allowed areas

To begin with, we should notice that the player is not free to place their towers wherever they want to on the map. In fact, they cannot place them along the path where the enemies are moving or in areas where there is water. Therefore, we need to implement this constraint.

Thus, we need to look at our map and find all the spots where the player can place the tower. In our case, the spots that we are looking for are the following:

As we can see, it has a custom shape. Even if it is possible to implement a custom shape, it can be much more convenient to think in terms of rectangles and then to split our shape into rectangles. Of course, this can be done in more than one way; however, using fewer rectangles to cover the entire area is better. On the other hand, by using more rectangles...