• Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    C#
  • License
    Other
  • Created about 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Source Code for 'Developing 2D Games with Unity: Independent Game Programming with C#' by Jared Halpern

Apress Source Code

This repository accompanies Developing 2D Games with Unity: Independent Game Programming with C# by Jared Halpern (Apress, 2018).

Cover image

Download the files as a zip using the green button, or clone the repository to your machine using Git.

Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

Contributions & Corrections

If you find any typos, errors in code, or otherwise incorrect information, please feel free to file an Issue in GitHub. See the file Contributing.md for more information on how you can further contribute to this repository.

General Notes

Credit: @RenatiusvanSander

As noted here, occasionally the Unity Editor will set the Z-coordinate on a newly created GameObject Transform to be negative. If this happens and the Z-coordinate is set to a negative number, you won't see it when the Scene plays. To fix this, change the Z-coordinate to be 0 on the GameObject Transform.

Errata

Chapter 3, Page 53

Credit: @omundy

After stopping the playing scene, add the animation for the player's idle state. From the Sprites folder, select the last two sprites from the Player32x32 sprite-sheet, titled: Player32x32_12 and Player32x32_13 and drag them onto the PlayerObject. When prompted by the Create New Animation save window, name the created animation-clip, "player-idle" and save to the Animations -> Animations folder.

Chapter 4

Credit: @josenerydev

Issue with format of file: OutdoorObjects.png. (fixed in GitHub repo)

Chapter 4, Page 93

In the Creating Tile Palettes section, the Tile Palette window in Unity 2018.3 is now located under Window -> 2D -> Tile Palette.

Chapter 4, Page 128

Credit: @omundy

Make sure to attach the RoundCameraPos script to the virtual camera object. Drag and drop the RoundCameraPos onto "CM vcam1".

Chapter 4, Page 137

Credit: @omundy

The interface has been updated in Unity 2018.3. The menu item "Edit Physics Shape" has been renamed to "Custom Physics Shape". After selecting Custom Physics Shape, click the "Generate" button on the right before editing.

Chapter 5, Page 147

Credit: @omundy

Create the GameObject in the hierarchy view (not project view).

Chapter 5, Page 161

Credit: @mprogers

In the Build the Consumable Script section, third paragraph, note that there is a distinction between the behavior of Scriptable Objects when running a project in the Editor, versus when running in a deployed (to device) build: Scriptable Objects cannot be used to save changes to data in a deployed build. More on this subject can be read here.

Chapter 5, Page 162

Credit: @omundy

In the Assembling Our Item section, third paragraph, rename the Scriptable Object, "Coin" (not "Item").

Chapter 5, Page 164

Credit: @omundy

In the Player Collisions section, the first line of code section // 3, should be:

print("Hit: " + hitObject.objectName);

Chapter 5, Page 166

Credit: @omundy

Steps 10 and 11 are duplicates of step 3 and can be disregarded.

Chapter 6, Page 198

Credit: @omundy

Under the heading Create the HealthBar Script, right-click in the MonoBehaviours folder and create a new C# script called HealthBar."

Chapter 6, Page 202-204

Credit: @omundy

Ensure a copy of the HealthBarObject is in the Hierarchy view and select it. Add the HealthBar script this HealthBarObject. When working with the HealthBar in these next 3 pages (202-204), work with the copy of HealthBarObject in the Hierarchy view, not the copy in the Prefab folder. Make sure to apply changes when you're done, so the changes propagate to the Prefab.

Note: The location of the button to apply changes to a prefab has changed in Unity 2018. The button is now located in the top right of the Inspector, in a drop-down menu called Overrides.

Chapter 6, Page 204

Credit: @omundy

The property, Character Category which appears in the source and in Figure 6-22 may be disregarded, or used later on in your game to broadly distinguish between what is/isn't an enemy, or the player (or even an NPC) instead of creating a tag for each character type.

Chapter 6, Page 207

Credit: @omundy

With InventoryObject selected, in the Canvas Scaler component, set Reference Pixels Per Unit to 32.

Chapter 7, Page 263

Credit: @omundy

In the The DamageCharacter() method section, the code should be added to the Enemy class.

Chapter 7, Page 269

Credit: @omundy

In the Refactoring Prefab Instantiation section, remove all four lines from Start() and add them to the new ResetCharacter() override.

After you add the ResetCharacter() method to the Player class, add the following method

private void OnEnable() {
	ResetCharacter();
}

Chapter 7, Page 275

Credit: @omundy

You'll notice when you run into the enemies they spin. Like you did with the PlayerObject, check Freeze Rotation for the Z axis inside the Rigidbody2D on the EnemyObject prefab.

Chapter 8, Page 287

Credit: @omundy

In the Enemy Walk Animation section, select the Enemy prefab then open the Animator window as seen in Figure 8-3.

Chapter 8, Page 357

Credit: @VADS

In the implementation of the GetQuadrant() method, disregard the first two variable declarations: Vector2 mousePosition = Input.mousePosition; and Vector2 playerPosition = transform.position; as they are not used.

Chapter 8, Page 360

Credit: @rdimitriev

In the method UpdateState(), the case for Quadrant.West: should be changed from: quadrantVector = new Vector2(-1.0f, 1.0f); to quadrantVector = new Vector2(-1.0f, 0.0f);

More Repositories

1

ray-tracing-gems

Source Code for "Ray Tracing Gems: High-Quality and Real-Time Rendering with DXR and Other APIs" by Eric Haines and Tomas Akenine-Möller
C
919
star
2

Ray-Tracing-Gems-II

Source Code for "Ray Tracing Gems II: Next Generation Real-Time Rendering with DXR, Vulkan, and OptiX" by Adam Marrs, Peter Shirley, and Ingo Wald
C++
692
star
3

low-level-programming

Source code for 'Low-Level Programming' by Igor Zhirkov
Assembly
644
star
4

design-patterns-in-modern-cpp

Source code for 'Design Patterns in Modern C++' by Dmitri Nesteruk
C++
534
star
5

pro-spring-5

Source code for 'Pro Spring 5' by Iuliana Cosmina, Rob Harrop, Chris Schaefer, and Clarence Ho
JavaScript
404
star
6

pro-asp.net-core-mvc-2

Source code for 'Pro ASP.NET Core MVC 2' by Adam Freeman
HTML
375
star
7

js-data-structures-and-algorithms

Source code for 'JavaScript Data Structures and Algorithms' by Sammie Bae
JavaScript
322
star
8

hands-on-time-series-analylsis-python

Source Code for 'Hands-on Time Series Analysis with Python' by B V Vishwas and Ashish Patel
Jupyter Notebook
321
star
9

python-projects-for-beginners

Source Code for 'Python Projects for Beginners' by Connor Milliken
Jupyter Notebook
297
star
10

pro-csharp-7

Source code for 'Pro C# 7' by Andrew Troelsen and Philip Japikse
C#
290
star
11

pro-react-16

Source Code for 'Pro React 16' by Adam Freeman
JavaScript
273
star
12

practical-tla-plus

Source Code for 'Practical TLA+' by Hillel Wayne
TLA
271
star
13

pro-angular-2ed

Source code for 'Pro Angular' by Adam Freeman
TypeScript
244
star
14

data-parallel-CPP

Source code for 'Data Parallel C++: Mastering DPC++ for Programming of Heterogeneous Systems using C++ and SYCL' by James Reinders, Ben Ashbaugh, James Brodman, Michael Kinsner, John Pennycook, Xinmin Tian (Apress, 2020).
CMake
240
star
15

pro-asp.net-core-3

Source Code for 'Pro ASP.NET Core 3' by Adam Freeman
JavaScript
211
star
16

beginning-python-3ed

Source code for 'Beginning Python' by Magnus Lie Hetland
Python
207
star
17

pro-angular-6

Source Code for 'Pro Angular 6' by Adam Freeman
TypeScript
193
star
18

pro-asp.net-mvc-5

Source code for 'Pro ASP.NET MVC 5' by Adam Freeman
PowerShell
189
star
19

pivotal-certified-pro-spring-dev-exam-02

Source Code for 'Pivotal Certified Professional Core Spring 5 Developer Exam' by Iuliana Cosmina
Java
168
star
20

frameworkless-front-end-development

Source code for 'Frameworkless Front-End Development' by Francesco Strazzullo
JavaScript
167
star
21

pro-TBB

Source Code for 'Pro TBB: C++ Parallel Programming with Threading Building Blocks' by Michael Voss, Rafael Asenjo, and James Reinders
C++
166
star
22

pro-c-sharp-10

Source Code for 'Pro C# 10 with .NET 6' by Andrew Troelsen and Phil Japikse
C#
162
star
23

def-guide-spring-batch

Source Code for The Definitive Guide to Spring Batch by Michael Minella
Java
159
star
24

pro-angular-9

Source Code for 'Pro Angular 9' by Adam Freeman
TypeScript
154
star
25

build-your-own-2d-game-engine

Source code for 'Build your own 2D Game Engine and Create Great Web Games' by Kelvin Sung, Jebediah Pavleas, Fernando Arnez, and Jason Pace
JavaScript
150
star
26

practical-ddd-in-enterprise-java

Source Code for 'Practical Domain-Driven Design in Enterprise Java' by Vijay Nair
Java
144
star
27

modern-x86-assembly-language-programming

Source code for 'Modern X86 Assembly Language Programming' by Daniel Kusswurm
Assembly
143
star
28

pro-go

Source Code for 'Pro Go' by Adam Freeman
Go
143
star
29

pro-.net-memory

Source Code for 'Pro .NET Memory Management' by Konrad Kokosa
C#
135
star
30

monetizing-machine-learning

Source code for 'Monetizing Machine Learning' by Manuel Amunategui and Mehdi Roopaei
Jupyter Notebook
131
star
31

programming-with-64-bit-ARM-assembly-language

Source Code for 'Programming with 64-Bit ARM Assembly Language: Single Board Computer Development for Raspberry Pi and Mobile Devices' by Stephen Smith
128
star
32

building-quality-shaders-unity

Source Code for 'Building Quality Shaders for Unity' by Daniel Ilett
ShaderLab
126
star
33

practical-flutter

Source Code for 'Practical Flutter' by Frank Zammetti
Dart
126
star
34

beginning-x64-assembly-programming

Source Code for 'Beginning x64 Assembly Programming' by Jo Van Hoey
Assembly
125
star
35

pro-asp.net-core-6

Source Code for 'Pro ASP.NET Core 6' by Adam Freeman
SCSS
124
star
36

pro-asp.net-core-mvc

Source code for 'Pro ASP.NET Core MVC' by Adam Freeman
CSS
123
star
37

os-x-ios-kernel-programming

Source code for 'OS X and iOS Kernel Programming' by Ole Henry Halvorsen and Douglas Clarke
C++
122
star
38

pro-vue-js-2

Source Code for Pro Vue.js 2 by Adam Freeman
Vue
116
star
39

practical-ml-w-python

Source code for 'Practical Machine Learning with Python' by Dipanjan Sarkar, Raghav Bali, and Tushar Sharma
Jupyter Notebook
113
star
40

pro-objective-c-design-patterns-for-ios

Source code for 'Pro Objective-C Design Patterns for iOS' by Carlo Chung
Objective-C
113
star
41

pro-spring-boot-2

Source Code for Pro Spring Boot 2 by Felipe Gutierrez
Java
111
star
42

beginning-cpp20

Source Code for 'Beginning C++20' by Ivor Horton and Peter Van Weert
C++
111
star
43

malware-analysis-detection-engineering

Source Code for 'Malware Analysis and Detection Engineering' by Abhijit Mohanta and Anoop Saldanha
C
109
star
44

programming-persistent-memory

Source Code for 'Programming Persistent Memory: A Comprehensive Guide for Developers' by Steve Scargall
C
109
star
45

numerical-python-second-ed

Source code for 'Numerical Python Second Edition' by Robert Johansson
Jupyter Notebook
109
star
46

network-prog-with-go

Source code for 'Network Programming with Go' by Jan Newmarch
Go
107
star
47

essential-typescript

Source Code for 'Essential TypeScript' by Adam Freeman
TypeScript
107
star
48

css-mastery-16

Source code for 'CSS Mastery' by Andy Budd and Emil Björklund
106
star
49

pivotal-certified-pro-spring-dev-exam

Source code for 'Pivotal Certified Professional Spring Developer Exam' by Iuliana Cosmina
Java
105
star
50

genetic-algorithms-in-java-basics

Source code for 'Genetic Algorithms in Java Basics' by Lee Jacobson and Burak Kanber
Java
104
star
51

machine-learning-with-pyspark

Source Code for 'Machine Learning with PySpark' by Pramod Singh
Jupyter Notebook
103
star
52

physically-based-shader-dev-for-unity-2017

Source code for 'Physically Based Shader Development for Unity 2017' by Claudia Doppioslash
C#
102
star
53

building-chatbots-with-python

Source Code for 'Building Chatbots with Python' by Sumit Raj
Jupyter Notebook
100
star
54

mastering-ml-w-python-in-six-steps

Source code for 'Mastering Machine Learning with Python in Six Steps' by Manohar Swamynathan
Jupyter Notebook
100
star
55

common-lisp-condition-system

Source Code for 'The Common Lisp Condition System' by Michal "phoe" Herda
Common Lisp
98
star
56

java-game-dev-LibGDX

Source Code for Java Game Development with LibGDX by Lee Stemkoski
Java
96
star
57

practical-rust-projects

Source Code for 'Practical Rust Projects' by Shing Lyu
Rust
93
star
58

spring-5-recipes

Source code for 'Spring 5 Recipes' by Marten Deinum, Daniel Rubio, and Josh Long
Java
93
star
59

Beg-STM32-Devel-FreeRTOS-libopencm3-GCC

Source code for 'Beginning STM32: Developing with FreeRTOS, libopencm3 and GCC' by Warren Gay
C
92
star
60

beg-cplusplus17

Source code for 'Beginning C++17' by Ivor Horton and Peter Van Weert
C++
91
star
61

esntl-angular-for-asp.net-core-mvc

Source code for 'Essential Angular for ASP.NET Core MVC' by Adam Freeman
HTML
88
star
62

pro-ef-core-2-for-asp.net-core-mvc

Source code for 'Pro Entity Framework Core 2 for ASP.NET Core MVC' by Adam Freeman
HTML
88
star
63

pro-design-patterns-in-swift

Source code for 'Pro Design Patterns in Swift' by Adam Freeman
Swift
87
star
64

practical-shader-dev

Source code for 'Practical Shader Development' by Kyle Halladay
C++
87
star
65

practical-web-scraping-for-data-science

Source code for 'Practical Web Scraping for Data Science' by Seppe vanden Broucke and Bart Baesens
Python
87
star
66

practical-python-ai-projects

Source code for 'Practical Python AI Projects' by Serge Kruk
Python
86
star
67

modern-full-stack-development

Source code for 'Modern Full-Stack Development' by Frank Zammetti
TypeScript
86
star
68

practical-django2-and-channels2

Source Code for 'Practical Django 2 and Channels 2' by Federico Marani
Python
86
star
69

practical-microservices-architectural-patterns

Source Code for 'Practical Microservices Architectural Patterns' by Binildas Christudas
Java
83
star
70

modern-x86-assembly-language-programming-2e

Source Code for 'Modern X86 Assembly Language Programming' by Daniel Kusswurm
C++
81
star
71

pro-deep-learning-w-tensorflow

Source code for 'Pro Deep Learning with TensorFlow' by Santanu Pattanayak
Jupyter Notebook
81
star
72

matlab-deep-learning

Source code for 'MATLAB Deep Learning' by Phil Kim
Python
80
star
73

practical-machine-learning-w-rust

Source Code for 'Practical Machine Learning with Rust' by Joydeep Bhattacharjee
Rust
80
star
74

design-patterns-c-sharp

Source Code for 'Design Patterns in C#' by Vaskaran Sarcar
C#
80
star
75

beginning-anomaly-detection-using-python-based-dl

Source Code for 'Beginning Anomaly Detection Using Python-Based Deep Learning' by Sridhar Alla and Suman Kalyan Adari
Jupyter Notebook
80
star
76

pro-wpf-4.5-in-csharp

Source code for 'Pro WPF 4.5 in C#' by Matthew MacDonald
C#
79
star
77

domain-driven-laravel

Source Code for 'Domain-Driven Laravel' by Jesse Griffin
PHP
77
star
78

pro-python-best-practices

Source code for 'Pro Python Best Practices' by Kristian Rother
Python
76
star
79

csharp-6.0-and-.net-4.6

Source code for 'C# 6.0 and the .NET 4.6 Framework' by Andrew Troelsen and Philip Japikse
C#
76
star
80

matlab-machine-learning

Source Code for 'MATLAB Machine Learning' by Michael Paluszek and Stephanie Thomas
MATLAB
74
star
81

building-javascript-games

Source code for 'Building JavaScript Games' by Arjan Egges
JavaScript
73
star
82

beg-cobol-for-programmers

Source code for 'Beginning COBOL for Programmers' by Michael Coughlan
COBOL
73
star
83

db-performance-at-scale

Source code for "Database Performance at Scale: A Practical Guide (Apress, 2023)," by Felipe Cardeneti Mendes, Piotr Sarna, Pavel Emelyanov & Cynthia Dunlop
73
star
84

programming-algorithms-lisp

Source Code for 'Programming Algorithms in Lisp' by Vsevolod Domkin
Common Lisp
73
star
85

practical-docker-with-python

Source Code for 'Practical Docker with Python' by Sathyajith Bhat
Python
72
star
86

Test-Driven-Development-in-Swift

Source code for the tutorials in the Test-Driven Development in Swift book
Swift
72
star
87

machine-learning-oil-gas-industry

Source Code for 'Machine Learning in the Oil and Gas Industry' by Yogendra Narayan Pandey, Ayush Rastogi, Sribharath Kainkaryam, Srimoyee Bhattacharya, and Luigi Saputelli
70
star
88

dom-scripting-10

Source code for 'DOM Scripting' by Jeremy Keith and Jeffrey Sambells
JavaScript
70
star
89

practical-cryptography-in-python

Source code for 'Cryptography in Python Source Code' by Seth Nielson and Christopher K. Monson
Python
69
star
90

text-analytics-w-python-2e

Source Code for 'Text Analytics with Python,' 2nd Edition by Dipanjan Sarkar
Jupyter Notebook
69
star
91

python-ml-case-studies

Source code for 'Python Machine Learning Case Studies' by Danish Haroon
68
star
92

foundation-game-design-w-html5-javascript

Source code for 'Foundation Game Design with HTML5 and JavaScript' by Rex van der Spuy
HTML
68
star
93

advanced-data-analytics-using-python

Source Code for 'Advanced Data Analytics Using Python' by Sayan Mukhopadhyay
Python
67
star
94

cryptography-in-c-cpp

Source code for 'Cryptography in C and C++' by Michael Welschenbach
C
67
star
95

android-espresso-revealed

Source Code for 'Android Espresso Revealed' by Denys Zelenchuk
Java
65
star
96

beg-spring-boot-2

Source code for 'Beginning Spring Boot 2' by K. Siva Prasad Reddy
Java
65
star
97

modern-arm-assembly-language-programming

Source Code for 'Modern Arm Assembly Language Programming' by Daniel Kusswurm
C++
63
star
98

python-data-analytics-2e

Source Code for 'Python Data Analytics, 2nd Edition' by Fabio Nelli
Jupyter Notebook
63
star
99

physics-for-game-programmers

Source code for 'Physics for Game Programmers' by Grant Palmer
Java
63
star
100

beg-iphone-dev-w-swift-3

Source code for 'Beginning iPhone Development with Swift 3' by Molly Maskrey, Kim Topley, David Mark, Fredrik Olsson, and JEFF LAMARCHE
Swift
63
star