Book Image

Learning Design Patterns with Unity

By : Harrison Ferrone
Book Image

Learning Design Patterns with Unity

By: Harrison Ferrone

Overview of this book

Struggling to write maintainable and clean code for your Unity games? Look no further! Learning Design Patterns with Unity empowers you to harness the fullest potential of popular design patterns while building exciting Unity projects. Through hands-on game development, you'll master creational patterns like Prototype to efficiently spawn enemies and delve into behavioral patterns like Observer to create reactive game mechanics. As you progress, you'll also identify the negative impacts of bad architectural decisions and understand how to overcome them with simple but effective practices. By the end of this Unity 2023 book, the way you develop Unity games will change. You'll emerge not just as a more skilled Unity developer, but as a well-rounded software engineer equipped with industry-leading design patterns.
Table of Contents (23 chapters)
21
Other Books You May Enjoy
22
Index

Building a controller adapter

Imagine you’re building an old-school top-down adventure game where players can run around an arena collecting items and jump over obstacles, using the traditional WASD and arrow keys. Nothing new in the mechanics department.

But now, suppose you wanted to spice things up and give players the ability to upgrade their movement controls, and you found the perfect mouse-follow and teleport script in a third-party library. Ideally, you’d like your existing game code to work with both the standard and mouse-follow movement controls, but you can’t modify the third-party script in any way. How would you make this scenario work?

Defining a target

The first step in our Adapter journey is creating a target interface, which holds all the responsibilities our adapter and adaptee classes are going to share. In the starter project, MovementController.cs and TeleportController.cs both have a way of moving the player, although the methods...