Learn the essentials of the Unity game engine, the C# programming language, and the art of object-oriented programming. This book is aimed at beginners with no knowledge or experience in game development or programming. Packed with examples, this Second Edition is up-to-date with the latest Unity standards and features as of 2023, and includes many adjustments to improve your experience. Starting with an introduction to Unity, you will learn the essentials of the engine: navigating the various windows, managing the objects that make up your game, and understanding the concepts that are fundamental to the engine. After that, you will gain a solid foundation in the concepts of object-oriented programming and the syntax of the C# language. Then the fun really begins, as you get hands-on experience building three playable example projects that drill you on the concepts you’ve learned until they stick. Guided at each step by author Casey Hardman, you will outline and implement bare-bones, simple games designed to exercise your development skills: a top-down obstacle course, a tower defense game, and a 3D playground that demonstrates Unity's physics features. As you progress through the book, you'll put to use more and more of the features of C# and Unity, adding tools to your belt and strengthening you as a game developer. By the time you’ve completed the book, you will be empowered to strike out on your own and build the game mechanics of your choice. What You Will Learn Understand the fundamentals of object-oriented computer programming and the C# programming language Leverage the features of Unity to implement game mechanics with reusable, clean, and elegant code Design and implement your own mechanics and independently solve problems as they arise Who Is This Book For Beginners who have no prior experience with programming or game development, who would like to learn to create games with a solid foundation that prepares them to further develop their skills.
Author(s): Casey Hardman
Edition: 2
Publisher: Apress
Year: 2023
Language: English
Pages: 428
Table of Contents
About the Author
About the Technical Reviewer
Introduction
Part I: Unity Fundamentals
Chapter 1: Installation and Setup
Unity Hub
Installing Our Code Editor
Installing Unity
Creating a Project
Summary
Chapter 2: Unity Basics
Windows
Project Window
Scene Window
Hierarchy Window
Inspector Window
Components
Adding GameObjects
Summary
Chapter 3: Manipulating the Scene
Transform Tools
Positions and Axes
Making a Floor
Scale and Unit Measurements
Summary
Chapter 4: Parents and Their Children
Child GameObjects
World vs. Local Coordinates
A Simple Building
Pivot Points
Summary
Chapter 5: Prefabs
Making and Placing Prefabs
Editing Prefabs
Overriding Values
Nested Prefabs
Prefab Variants
Summary
Part II: Programming Fundamentals
Chapter 6: Programming Primer
Programming Languages and Syntax
What Code Does
Strong vs. Weak Typing
File-Type Extensions
Scripts
Summary
Chapter 7: Code Blocks and Methods
Statements and Semicolons
Code Blocks
Comments
Methods
Calling Methods
Basic Data Types
Returning Values with Methods
Declaring Methods
Operators
Summary
Chapter 8: Conditions
The “if” Block
Overloads
Enums
The “else” Block
The “else if” Block
Operators for Conditions
Equality Operators
Greater Than and Less Than
Or
And
Summary
Chapter 9: Working with Objects
Classes
Variables
Accessing Class Members
Instance Methods
Declaring Constructors
Using the Constructor
Static Members
Summary
Chapter 10: Working with Scripts
Usings and Namespaces
Script Class
Rotating a Transform
Frames and Seconds
Attributes
Summary
Chapter 11: Inheritance
Inheritance in Action: RPG Items
Declaring Our Classes
Constructor Chaining
Subtypes and Casting
Type Checking
Virtual Methods
Number Value Types
Summary
Chapter 12: Debugging
Setting Up the Debugger
Breakpoints
Using Unity’s Documentation
Summary
Part III: Obstacle Course
Chapter 13: Obstacle Course Design and Outline
Gameplay Overview
Technical Overview
Player Controls
Death and Respawn
Levels
Level Selection
Obstacles
Project Setup
Summary
Chapter 14: Player Movement
Player Setup
Materials and Colors
Applying Materials
Declaring Our Variables
Properties
Tracking the Velocity
Applying the Movement
Summary
Chapter 15: Death and Respawning
Enabling and Disabling
Death Method
Respawn Method
Summary
Chapter 16: Basic Hazards
Collision Detection
Hazard Script
Projectile Script
Shooting Script
Summary
Chapter 17: Walls and Goals
Walls
Goals
Build Settings for Scenes
Summary
Chapter 18: Patrolling Hazards
Resembling a Patrol Point
Arrays
Setting Up Patrol Points
Detecting Patrol Points
The “for” Loop
Sorting Patrol Points
Moving the Patroller
Summary
Chapter 19: Wandering Hazards
Wander Regions
Wanderer Setup
Wanderer Script
Handling the State
Reacting to the State
Summary
Chapter 20: Dashing
Dashing Variables
Dashing Method
Final Touches
Summary
Chapter 21: Designing Levels
Mixing Components
Four-Way Shooters
Spinning Blades
Blade Carousels
Prefabs and Variants
Making Levels
Adding Walls
Level View Camera
Summary
Chapter 22: Menus and UI
UI Solutions
Immediate Mode GUI (IMGUI)
Unity UI (uGUI)
UI Toolkit
Scene Flow
Level Selection Script
Summary
Chapter 23: In-Game Pause Menu
Freezing Time
Summary
Chapter 24: Spike Traps
Designing the Trap
Raising and Lowering
Writing the Script
Adding Collisions
Summary
Chapter 25: Obstacle Course Conclusion
Building the Project
Player Settings
Recap
Additional Features
Summary
Part IV: Tower Defense
Chapter 26: Tower Defense Design and Outline
Gameplay Overview
Technical Overview
Project Setup
Summary
Chapter 27: Camera Movement
Setting Up
Arrow Key Movement
Applying Movement
Mouse Dragging
Zooming
Summary
Chapter 28: Enemies and Projectiles
Layers and Physics
Basic Enemies
Projectiles
Summary
Chapter 29: Towers and Targeting
Targeters
Tower Inheritance
Tower
TargetingTower
FiringTower
Upper Classes
Arrow Towers
Summary
Chapter 30: Build Mode UI
UI Basics
The RectTransform
Building Our UI
Summary
Chapter 31: Building and Selling
Events
Setting Up
Build Mode Logic
The Dictionary
OnClick Event Methods
Summary
Chapter 32: Play Mode Logic
Spawn and Leak Points
Locking the Play Button
Pathfinding Setup
Finding a Path
Summary
Chapter 33: Enemy Logic
Play Mode Setup
Spawning Enemies
Enemy Movement
Summary
Chapter 34: More Tower Types
Arcing Projectiles
Cannon Tower
Hot Plates
Barricades
Summary
Chapter 35: Tower Defense Conclusion
Inheritance
UI
Raycasting
Pathfinding
Additional Features
Health Bars
Types for Armor and Damage
More Complex Pathing
Range Indicators
Upgrading Towers
Summary
Part V: Physics Playground
Chapter 36: Physics Playground Design and Outline
Feature Outline
Camera
Player Movement
Pushing and Pulling
Moving Platforms
Joints and Swings
Force Fields and Jump Pads
Project Setup
Summary
Chapter 37: Mouse-Aimed Camera
Player Setup
How It Works
Script Setup
Hotkeys
Mouse Input
First-Person Mode
Third-Person Mode
Testing
Summary
Chapter 38: Advanced 3D Movement
How It Works
Player Script
Movement Velocity
Applying Movement
Losing Velocity
Gravity and Jumping
Summary
Chapter 39: Wall Jumping
Variables
Detecting Walls
Performing the Jump
Summary
Chapter 40: Pulling and Pushing
Script Setup
FixedUpdate
Target Detection
Pulling and Pushing
Cursor Drawing
Summary
Chapter 41: Moving Platforms
Platform Movement
Platform Detection
Summary
Chapter 42: Joints and Swings
Swing Setup
Connecting the Joints
Summary
Chapter 43: Force Fields and Jump Pads
Script Setup
Force Field Setup
Adding Velocity to the Player
Applying Forces
Summary
Chapter 44: Conclusion
Physics Playground Recap
Further Learning for Unity
The Asset Store
Coroutines
Script Execution Order
Further Learning for C#
Delegates
Documentation Comments
Exceptions
Advanced C#
Operator Overloading
Conversions
Generic Types
Structs
Summary
Index