Developing 2D Games with Unity (eBook)
XXII, 383 Seiten
Apress (Verlag)
978-1-4842-3772-4 (ISBN)
Follow a walkthrough of the Unity Engine and learn important 2D-centric lessons in scripting, working with image assets, animations, cameras, collision detection, and state management. In addition to the fundamentals, you'll learn best practices, helpful game-architectural patterns, and how to customize Unity to suit your needs, all in the context of building a working 2D game.
While many books focus on 3D game creation with Unity, the easiest market for an independent developer to thrive in is 2D games. 2D games are generally cheaper to produce, more feasible for small teams, and more likely to be completed. If you live and breathe games and want to create them then 2D games are a great place to start.
By focusing exclusively on 2D games and Unity's ever-expanding 2D workflow, this book gives aspiring independent game developers the tools they need to thrive. Various real-world examples of independent games are used to teach fundamental concepts of developing 2D games in Unity, using the very latest tools in Unity's updated 2D workflow.
New all-digital channels for distribution, such as Nintendo eShop, XBox Live Marketplace, the Playstation Store, the App Store, Google Play, itch.io, Steam, and GOG.com have made it easier than ever to discover, buy, and sell games. The golden age of independent gaming is upon us, and there has never been a better time to get creative, roll up your sleeves, and build that game you've always dreamed about. Developing 2D Games with Unity can show you the way.
What You'll Learn
- Delve deeply into useful 2D topics, such as sprites, tile slicing, and the brand new Tilemap feature.
- Build a working 2D RPG-style game as you learn.
- Construct a flexible and extensible game architecture using Unity-specific tools like Scriptable Objects, Cinemachine, and Prefabs.
- Take advantage of the streamlined 2D workflow provided by the Unity environment.
- Deploy games to desktop
Who This Book Is For
Hobbyists with some knowledge of programming, as well as seasoned programmers interested in learning to make games independent of a major studio.
Jared Halpern is a software developer with over 12 years of experience working in a wide range of technologies. Lately he has specialized in Apple and Unity. Jared has built many iPhone apps over the years, including games, augmented reality, photography, eCommerce, video, and GIF apps. His interests include Swift, Unity, AR, Game Development, and the creative application of these technologies. He has an immense passion for the potential of games as an interactive medium to tell stories and give experiences in ways that other mediums cannot. He currently enjoys working as a freelance software developer.
Follow a walkthrough of the Unity Engine and learn important 2D-centric lessons in scripting, working with image assets, animations, cameras, collision detection, and state management. In addition to the fundamentals, you'll learn best practices, helpful game-architectural patterns, and how to customize Unity to suit your needs, all in the context of building a working 2D game. While many books focus on 3D game creation with Unity, the easiest market for an independent developer to thrive in is 2D games. 2D games are generally cheaper to produce, more feasible for small teams, and more likely to be completed. If you live and breathe games and want to create them then 2D games are a great place to start. By focusing exclusively on 2D games and Unity's ever-expanding 2D workflow, this book gives aspiring independent game developers the tools they need to thrive. Various real-world examples of independent games are used to teach fundamental concepts of developing2D games in Unity, using the very latest tools in Unity's updated 2D workflow. New all-digital channels for distribution, such as Nintendo eShop, XBox Live Marketplace, the Playstation Store, the App Store, Google Play, itch.io, Steam, and GOG.com have made it easier than ever to discover, buy, and sell games. The golden age of independent gaming is upon us, and there has never been a better time to get creative, roll up your sleeves, and build that game you've always dreamed about. Developing 2D Games with Unity can show you the way.What You'll LearnDelve deeply into useful 2D topics, such as sprites, tile slicing, and the brand new Tilemap feature.Build a working 2D RPG-style game as you learn.Construct a flexible and extensible game architecture using Unity-specific tools like Scriptable Objects, Cinemachine, and Prefabs.Take advantage of the streamlined 2D workflow provided by the Unity environment. Deploy games to desktopWho This Book Is For Hobbyists with some knowledge of programming, as well as seasoned programmers interested in learning to make games independent of a major studio.
Jared Halpern is a software developer with over 12 years of experience working in a wide range of technologies. Lately he has specialized in Apple and Unity. Jared has built many iPhone apps over the years, including games, augmented reality, photography, eCommerce, video, and GIF apps. His interests include Swift, Unity, AR, Game Development, and the creative application of these technologies. He has an immense passion for the potential of games as an interactive medium to tell stories and give experiences in ways that other mediums cannot. He currently enjoys working as a freelance software developer.
Table of Contents 4
About the Author 13
About the Technical Reviewer 14
Acknowledgments 15
Preface 16
About This Book 18
Chapter 1: Games and Game Engines 20
Game Engines—What Are They? 20
The First Way to Build a House 23
The Second Way to Build a House 23
About the First Approach 24
About the Second Approach 24
In conclusion … 25
Game Engines Historically 25
Game Engines Today 27
The Unity Game Engine 29
Summary 31
Chapter 2: Introduction to Unity 32
Install Unity 32
Configure Unity 33
On Disk 34
In the Cloud 34
The Script Editor: Visual Studio 36
Navigating the Unity Interface 37
Understanding the Different Window Views 37
Configure and Customize the Layout 41
The Transform Toolset 42
Handle Position Controls 44
Play, Pause, and Step Controls 45
Unity Project Structure 47
Unity Documentation 48
Summary 48
Chapter 3: Foundations 50
Game Objects: Our Container Entities 50
Entity-Component Design 52
Components: Building Blocks 54
Sprites 54
Animations 64
The Animator State Machine 68
Colliders 73
The Rigidbody Component 75
Tags and Layers 76
Tags 76
Layers 77
Sorting Layers 78
Introducing: Prefabs 82
Scripts: Logic for Components 84
State and Animations 94
More State Machines 94
Animation Parameters 97
Summary 109
Chapter 4: World Building 110
Tilemaps and Tile Palettes 110
Creating Tile Palettes 112
Painting with Tile Palettes 115
The Tile Palette 116
Working with Multiple Tilemaps 120
Graphics Settings 125
The Camera 126
Using Cinemachine 130
Installing Cinemachine in Unity 2017 130
Installing Cinemachine in Unity 2018 131
After Installing Cinemachine 132
Virtual Cameras 133
Cinemachine Confiner 139
Stabilization 144
Materials 148
Colliders and Tilemaps 149
Tilemap Collider 2D 149
Composite Colliders 152
Editing Physics Shapes 156
Summary 160
Chapter 5: Assembling the Nuts and Bolts 161
Character Class 161
Player Class 163
Focus on Prefabs 165
Create a Coin Prefab 165
Set Up the Circle Collider 2D 166
Set Up a Custom Tag 167
Layer-Based Collision Detection 169
Triggers and Scripting 172
Scriptable Objects 174
Creating a Scriptable Object 175
Build the Consumable Script 179
Assembling Our Item 180
Player Collisions 182
Creating a Heart Power-Up 183
Summary 191
Chapter 6: Health and Inventory 192
Creating a Health Bar 192
Canvas Objects 192
UI Elements 193
Building the Health Bar 193
Anchors 196
Adjusting the Anchor Points 198
UI Image Masks 201
Importing Custom Fonts 205
Adding Hit-Points Text 206
Scripting the Health Bar 209
Scriptable Object: HitPoints 209
Update the Character Script 210
Update the Player Script 211
Create the HealthBar Script 215
Configure the Health Bar Component 219
Inventory 223
Import the Inventory Slot Image 226
Configure the Inventory Slot 227
Configure the ItemImage 227
Configure the Background 228
Configure the Tray 229
Configure QtyText—the Quantity Text 230
Create the Prefabs 231
Build the Slot Script 232
Create the Inventory Script 235
Set-Up Properties 235
Instantiate the Slot Prefabs 237
Fill in the Start() Method 239
The AddItem Method 240
Update the Player Script 245
One Last Thing … 246
Summary 248
Chapter 7: Characters, Coroutines, and Spawn Points 249
Create a Game Manager 249
Singletons 250
Creating the Singleton 251
Build a GameManager Prefab 254
Spawn Points 254
Build a Spawn Point Prefab 257
Configure the Player Spawn Point 261
Spawn the Player 262
In Summary 264
A Spawn Point for Enemies 265
Camera Manager 267
Using the Camera Manager 269
Character Class Design 272
The Virtual Keyword 272
The Enemy Class 273
Refactoring 273
The Internal Access Modifier 274
Coroutines 275
Invoking Coroutines 276
Pausing or “Yielding” Execution 276
A Complete Coroutine 276
Coroutines with Time Intervals 277
The Abstract Keyword 277
Implementing the Enemy Class 279
The DamageCharacter() method 279
ResetCharacter() 282
Calling ResetCharacter() in OnEnable() 283
KillCharacter() 283
Updating the Player Class 283
Refactoring Prefab Instantiation 285
Review 286
Using What We’ve Built 287
OnCollisionEnter2D 288
OnCollisionExit2D 289
Configure the Enemy Script 290
Summary 291
Chapter 8: Artificial Intelligence and Slingshots 292
The Wander Algorithm 292
Getting Started 293
Create the Wander Script 294
Wander Variables 295
Build Out Start() 297
The Wander Coroutine 298
Choosing a New Endpoint 300
Angles to Radians to Vectors! 302
Enemy Walk Animation 302
The Move() Coroutine 306
Configure Wander Script 309
OnTriggerEnter2D() 310
OnTriggerExit2D() 312
Gizmos 314
Self-Defense 317
Classes Needed 318
Ammo Class 318
Import the Assets 319
Add Components, Set Layers 319
Update the Layer Collision Matrix 320
Build the Ammo Script 321
Before We Forget ... Make the AmmoObject Prefab 323
Object Pooling 323
Building the Weapon Class 325
Stubbing-Out Methods 328
The SpawnAmmo Method 330
The Arc Class and Linear Interpolation 332
Screen Points and World Points 335
The FireAmmo Method 336
Configure the Weapon Script 338
Arcing 339
Animating the Slingshot 341
Animation and Blend Trees 341
Blend Trees 342
Clean Up the Animator 343
Build the Walking Blend Tree 344
Layers, All the Way Down 347
A Note About Blend Types 348
Animation Parameters 348
Use the Parameters 350
Ok, but Why ? 352
Loop Time 354
Create the Transitions 354
Updating the Movement Controller 355
Import the Fight Sprites 357
Create Animation Clips 357
Build the Fighting Blend Tree 359
Exit Time 361
Update the Weapon Class 362
Add the Variables 362
Start() 364
Update Update() 365
Determining Direction 365
The Slope Method 368
Calculate the Slopes 369
Comparing y-Intercepts 370
HigherThanNegativeSlopeLine() 371
The GetQuadrant() method 372
The UpdateState() Method 374
Flicker When Damaged 377
Update the Player and Enemy Classes 378
Building for Platforms 379
Exiting the Game 382
Summary 382
What’s Next 383
Communities 383
Learn More 384
Where to Find Help 384
Game Jams 385
News and Articles 386
Games and Assets 386
Beyond! 386
Index 388
Erscheint lt. Verlag | 28.11.2018 |
---|---|
Zusatzinfo | XXII, 383 p. 210 illus., 193 illus. in color. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Mathematik / Informatik ► Informatik ► Programmiersprachen / -werkzeuge |
Informatik ► Software Entwicklung ► Spieleprogrammierung | |
Schlagworte | 2D • Android • C# • Development • game engines • Game Programming • independent game development • Indie Games • Ios • startup development • UNITY |
ISBN-10 | 1-4842-3772-2 / 1484237722 |
ISBN-13 | 978-1-4842-3772-4 / 9781484237724 |
Haben Sie eine Frage zum Produkt? |
Größe: 16,1 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich