Game Development with Unity for .NET Developers: The ultimate guide to creating games with Unity and Microsoft Game Stack
By Jiadong Chen and Ed Price
()
About this ebook
Understand what makes Unity the world’s most widely used real-time 3D development platform and explore its powerful features for creating 3D and 2D games, as well as the Unity game engine and the Microsoft Game Dev, including the Microsoft Azure Cloud and Microsoft Azure PlayFab services, to create games.
You will start by getting acquainted with the Unity editor and the basic concepts of Unity script programming with C#. You'll then learn how to use C# code to work with Unity's built-in modules, such as UI, animation, physics, video, and audio, and understand how to develop a game with Unity and C#. As you progress through the chapters, you'll cover advanced topics such as the math involved in computer graphics and how to create a custom render pipeline in Unity with the new Scriptable Render Pipeline, all while optimizing performance in Unity. Along the way, you'll be introduced to Microsoft Game Dev, Azure services, and Azure PlayFab, and using the Unity3D PlayFab SDK to access the PlayFab API.
By the end of this Unity book, you'll have become familiar with the Unity engine and be ready to develop your own games while also addressing the performance issues that you could encounter in the development process.
Related to Game Development with Unity for .NET Developers
Related ebooks
Unity 2022 by Example: A project-based guide to building 2D and 3D games, enhanced for AR, VR, and MR experiences Rating: 0 out of 5 stars0 ratingsUnity All-In-One Rating: 0 out of 5 stars0 ratingsBuilding your First Mobile Game using XNA 4.0 Rating: 0 out of 5 stars0 ratingsBuilding a 3D Game with LibGDX Rating: 1 out of 5 stars1/5Unity Game Development Blueprints Rating: 0 out of 5 stars0 ratingsUnity AI Programming Essentials Rating: 0 out of 5 stars0 ratingsGetting Started with Unity 5 Rating: 5 out of 5 stars5/5Beginning Unity Editor Scripting: Create and Publish Your Game Tools Rating: 0 out of 5 stars0 ratingsUnity 3D Game Development: Designed for passionate game developers—Engineered to build professional games Rating: 0 out of 5 stars0 ratingsUnity Multiplayer Games Rating: 5 out of 5 stars5/5Learning Unreal® Engine iOS Game Development Rating: 0 out of 5 stars0 ratingsUnity 2018 By Example: Learn about game and virtual reality development by creating five engaging projects, 2nd Edition Rating: 0 out of 5 stars0 ratingsBeginning Unity Android Game Development: From Beginner to Pro Rating: 0 out of 5 stars0 ratingsHands-On Game Development without Coding: Create 2D and 3D games with Visual Scripting in Unity Rating: 0 out of 5 stars0 ratingsUnity from Zero to Proficiency (Foundations) Fifth Edition: Unity from Zero to Proficiency, #1 Rating: 5 out of 5 stars5/5Building Android Games with Cocos2d-x Rating: 0 out of 5 stars0 ratingsGetting Started with Unity 2018: A Beginner's Guide to 2D and 3D game development with Unity Rating: 0 out of 5 stars0 ratingsBecoming Comfortable with Unity Rating: 0 out of 5 stars0 ratingsLearning Cocos2d-JS Game Development Rating: 0 out of 5 stars0 ratingsBuilding an FPS Game with Unity Rating: 0 out of 5 stars0 ratingsUnreal Engine 4 Game Development Quick Start Guide: Programming professional 3D games with Unreal Engine 4 Rating: 0 out of 5 stars0 ratingsMind-Melding Unity and Blender for 3D Game Development: Unleash the power of Unity and Blender to create amazing games Rating: 0 out of 5 stars0 ratingsBuilding a Game with Unity and Blender Rating: 0 out of 5 stars0 ratingsUnity Artificial Intelligence Programming: Add powerful, believable, and fun AI entities in your game with the power of Unity Rating: 0 out of 5 stars0 ratingsGodot Engine Game Development Projects: Build five cross-platform 2D and 3D games with Godot 3.0 Rating: 3 out of 5 stars3/5A Beginner's Guide to 2D Shooter Games: Beginners' Guides, #2 Rating: 0 out of 5 stars0 ratingsUnity from Zero to Proficiency (Intermediate): Unity from Zero to Proficiency, #3 Rating: 2 out of 5 stars2/5Building an RPG with Unreal 4.x Rating: 0 out of 5 stars0 ratingsMaster Procedural Generation with Unity and C# Rating: 0 out of 5 stars0 ratingsUnity Virtual Reality Projects: Explore the world of virtual reality by building immersive and fun VR projects using Unity 3D Rating: 0 out of 5 stars0 ratings
Programming For You
C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Coding with JavaScript For Dummies Rating: 0 out of 5 stars0 ratingsHTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Narrative Design for Indies: Getting Started Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5Beginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5C# 7.0 All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsC All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5
Reviews for Game Development with Unity for .NET Developers
0 ratings0 reviews
Book preview
Game Development with Unity for .NET Developers - Jiadong Chen
BIRMINGHAM—MUMBAI
Game Development with Unity for .NET Developers
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Pavan Ramchandani
Publishing Product Manager: Aaron Tanna
Senior Editor: Aamir Ahmed
Content Development Editor: Feza Shaikh
Technical Editor: Joseph Aloocaran
Copy Editor: Safis Editing
Project Coordinator: Manthan Patel
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Production Designer: Aparna Bhagat
Marketing Coordinator: Anamika Singh
First published: May 2022
Production reference: 2130522
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80107-807-8
www.packt.com
This book is dedicated to my wife, Yi Liang, for her encouragement and support, especially during the COVID-19 pandemic; her positive attitude toward life has inspired me and helped me through difficult times.
– Jiadong Chen
Foreword
A delayed game is eventually good, but a rushed game is forever bad.
– Industry catchphrase
You now hold in your hands the tools to make great games. If this was a Mario game, then you just punched a question mark block, and then a glowing, flashing, smoking mushroom just rose out of it. If this was a Zelda game, then you just navigated a boss dungeon, found a treasure chest, pulled this book out of it, and raised the book high above your head (with some suitable music playing). In other words, you just acquired a key powerup for your quest.
You can feel that dedication to excellence (which the industry quote refers to) when you play Nintendo games, Halo, Minecraft, and Sonic the Hedgehog (and pretty much whatever your favorite game is). Now you have the same opportunity: you can use your knowledge and your new Unity skills (granted, you probably haven't learned them yet) to make a powerful statement through your work.
Nintendo's philosophy is to never go the easy path; it's always to challenge ourselves and try to do something new.
– Shigeru Miyamoto (2005)
So that's why Nintendo makes some great games (and some really weird ones)! Regardless, here's your chance to make something that's unique and that really shows who you are. With these tools, your passion opens limitless opportunities.
And that brings us to a Microsoft quote (you knew it was coming).
Learning to fly is not pretty, but flying is.
– Satya Nadella, Hit Refresh
You learn tools to create masterpieces (or to at least get a job, or a better one). It's not easy to learn these new tools, but after you gain this knowledge, you can make great games.
Game Development with Unity for .NET Developers makes that process a whole lot easier! Unity is the world's most widely used, real-time 3D development platform for a reason! If you approach Unity with the .NET Framework, then you can leverage the power of C#, Microsoft Game Dev tools, Microsoft Azure Cloud services, and Azure PlayFab. You'll also see how these resources work seamlessly with Visual Studio and GitHub.
Our author, Jiadong Chen, used to work at Unity Technologies as a field engineer. He's been working in this .NET and Unity gaming stack for over 9 years. He's a member of the .NET Foundation, and has been a Microsoft MVP (Most Valuable Professional) for 6 years. (That means he's been awarded the title every year since 2015, based on his impact on the Microsoft developer community.) As you can imagine, his MVP award category is Developer Technologies. In other words, Jiadong is the perfect person to teach you how to use the .NET Framework and Microsoft developer stack to learn how to develop with the Unity game engine and how to take your games to the next level!
Make no mistake: as the title implies, this is a book for .NET developers to learn Unity. First, Jiadong starts with the basics of the Unity game engine. Then, you'll dig into scripting, using Unity to build your game UI, animating your game graphics, building physics, and adding audio and video (the basic components of building your game). Next, Jiadong gets into game math, while also using a rendering pipeline, data-oriented tech, a serialization system, and assets management. Finally, he shows you how to leverage the Microsoft Game Dev suite of technologies, Azure Cloud, and Azure PlayFab as you develop with the Unity engine.
In Game Development with Unity for .NET Developers, Jiadong Chen takes you on a tour, explaining the concepts with images and examples, so that you can fully understand each topic. He then takes you through the process, using real code, so that you can implement your own solutions. The process of learning how to develop games isn't easy, but this book will make it a lot easier.
After you're done reading the book, if life was a Mario game, you'll have grabbed the flag at the top of the flag pole and entered a sewer pipe! If this was a Zelda game, you'll have collected the Triforce. And if it's a Sonic game, then you just beat Dr. Robotnik in a giant robot mech that looks like him. As Satya Nadella implied, learning to fly won't be easy, but once you're done, you're going to be able to really take off and do some great things with Unity!
Ed Price
Senior Program Manager of Architectural Publishing
Microsoft, Azure Architecture Center (http://aka.ms/Architecture) Co-author of seven books, including Meg the Mechanical Engineer, The Azure Cloud Native Architecture Mapbook (Packt), and ASP.NET Core 5 for Beginners (Packt)
Contributors
About the author
Jiadong Chen is one of 3,000 international Microsoft® Most Valuable Professional (MVP) award winners, recognized by Microsoft as one of the technology industry's best and brightest six years in a row, and is currently working as a senior software developer at Company-X, based in Hamilton, New Zealand.
He specializes in the Microsoft Azure cloud, Unity and XR development, and .NET/C#. He is a Microsoft Certified Azure Solutions Architect Expert, a Microsoft Certified Azure Developer, a Microsoft Certified Azure AI Engineer, and a Microsoft Certified Trainer. He is also a member of the .NET Foundation.
Before joining Company-X, Jiadong worked for Unity, the creator of the world's most widely used real-time 3D development platform, as a field engineer.
After this long adventure, I would first like to thank my wife for her support. Writing a book is not an easy task, especially during the COVID-19 pandemic, and my wife's support has given me the psychological comfort to overcome the difficulties and finish the book.
A special thanks to the Packt team (especially Aaron, Manthan, and Feza) for being with me on this journey.
About the reviewer
Simon Jackson is a long-time software engineer and architect with many years of Unity game development experience, as well as an author of several Unity game development titles. He loves to both create Unity projects and lend a hand to help educate others, whether it's via a blog, vlog, user group, or major speaking event.
He currently works at a mixed-reality research lab called xRealityLabs, building the future of digital solutions for the construction and medical industries.
His primary focus at the moment is on the Reality Toolkit project, which is aimed at building a cross-platform mixed-reality framework to enable both VR and AR developers to build efficient solutions in Unity.
Table of Contents
Preface
Part 1: Basic Unity Concepts
Chapter 1: Hello Unity
Technical requirements
Getting started with the Unity Editor
Choosing the right Unity release for you
Choosing the right subscription plan for you
Downloading and installing the Unity Editor
Exploring the Unity Editor
Working with different features in Unity
What is a game engine?
Features in Unity
.NET/C# and scripting in Unity
.NET profiles in Unity
Scripting backends in Unity
Building Unity games with Visual Studio
Summary
Chapter 2: Scripting Concepts in Unity
Technical requirements
Understanding the concepts of scripting in Unity
GameObject-components architecture
Common classes in Unity
Prefabs in Unity
Special folders in Unity
The life cycle of a script instance
Initialization
Update
Rendering
Creating a script and using it as a component
How to create a new script in Unity
Adding a script as a component to a GameObject in the Scene
Accessing a component attached to a GameObject
Packages and the Unity Package Manager
Unity Package Manager
Package
Summary
Part 2: Using C# Scripts to Work with Unity's Built-In Modules
Chapter 3: Developing UI with the Unity UI System
C# scripts and common UI components in Unity
Canvas
Image
Text
Selectable UI components
C# scripts and the UI Event System in Unity
Input Modules
The new Input System package
The Model-View-ViewModel (MVVM) pattern and the UI
Performance tips to increase performance of the UI
The Unity Profiler
Multiple canvases
Use Sprite Atlas
Summary
Chapter 4: Creating Animations with the Unity Animation System
Technical requirements
Exploring the Unity animation system's concepts
Animation Clips
Animator Controller
Avatar
Animator component
Implementing 3D animation in Unity
Importing animation assets
Configuring the Animator Controller
Implementing 2D animation in Unity
Improving the performance of Unity's animation system
The Unity Profiler
Animator's Culling Mode
Anim. Compression
Summary
Chapter 5: Working with the Unity Physics System
Technical requirements
Concepts in the Unity Physics system
Collider
Rigidbody
Trigger
Scripting with the Physics system
Collision methods
Trigger methods
Methods of Rigidbody
Creating a simple game based on the Physics system
Increasing the performance of the Physics system
The Unity Profiler
Increasing the fixed timestep
Reducing unnecessary layer-based collision detections
Summary
Chapter 6: Integrating Audio and Video in a Unity Project
Technical requirements
Concepts in Unity's audio system and video system
Audio clips
Audio Sources
Audio Listener
Video clips
Video Player
Scripting with audio and video
AudioSource.Play
AudioSource.Pause
AudioSource.Stop
VideoPlayer.clip
VideoPlayer.url
VideoPlayer.Play
VideoPlayer.frame and VideoPlayer.frameCount
Things to note when using Unity to develop web applications
URL
Frame rate
Increasing the performance of the audio system
The Unity Profiler
Using Force To Mono to save memory
Summary
Part 3: Advanced Scripting in Unity
Chapter 7: Understanding the Mathematics of Computer Graphics in Unity
Getting started with coordinate systems
Understanding left-handed and right-handed coordinate systems
Local space
World space
Screen space
Working with vectors
Vector addition
How to subtract vectors
Dot product
Cross product
Working with the transformation matrix
Translation matrix
Rotation matrix
Scaling matrix
Working with quaternions
Creating rotations
Manipulating rotations
Working with Euler angles
Summary
Chapter 8: The Scriptable Render Pipeline in Unity
An introduction to the Scriptable Render Pipeline
The Fontainebleau Demo
The Spaceship Demo
The BoatAttack Demo
The Heretic: Digital Human
The Heretic: VFX Character
Universal Render Pipeline
The High Definition Render Pipeline
Working with Unity's Universal Render Pipeline
Exploring the sample scene
The Universal Render Pipeline asset
The Volume framework and post-processing
The Universal Render Pipeline shaders and materials
Commonly used shaders
Upgrading project materials to Universal Render Pipeline materials
Creating a shader and a Shader Graph
Increasing performance of the Universal Render Pipeline
The Frame Debugger
The SRP Batcher
Summary
Chapter 9: The Data-Oriented Technology Stack in Unity
Technical requirements
DOTS overview
Object-oriented design pattern versus DOTS
C# Job System
ECS
The Burst compiler
Multithreading and the C# Job System in Unity
Coroutines
async/await
Working with the C# Job System
Working with ECS in Unity
Using C# and the Burst compiler
Summary
Chapter 10: Serialization System and Assets Management in Unity and Azure
Technical requirements
Serialization system in Unity
What is Unity's serialization system?
The assets workflow in Unity
GUID and File ID
Meta files
The AssetPostprocessor class and the import pipeline
The Library folder
Introducing the special folders in Unity
Resources folder
StreamingAssets folder
Azure Blob storage with Unity's Addressable Asset system
Setting up an Azure Blob storage service
Installing the Addressable Assets system package
Building addressable content
Deploying content to the Azure Cloud
Loading addressable content from the Azure Cloud
Summary
Chapter 11: Working with Microsoft Game Dev, Azure Cloud, PlayFab, and Unity
Technical requirements
Introducing Microsoft Game Dev, Microsoft Azure Cloud, and Azure PlayFab
Microsoft Game Dev
Microsoft Azure Cloud
Azure PlayFab
Setting up Azure PlayFab for a Unity project
Creating a new Azure PlayFab account
Setting up a game studio and a game title in Azure PlayFab
Setting up the Azure PlayFab SDK in the Unity project
Signing up and logging in players using Azure PlayFab in Unity
Signing up players in Azure PlayFab
Logging in players in Azure PlayFab
Implementing a leaderboard using Azure PlayFab in Unity
Setting up a leaderboard in Azure PlayFab
Updating the score of a player from Unity using the Azure PlayFab API
Loading the leaderboard data from Azure PlayFab in Unity
Summary
Other Books You May Enjoy
Preface
As one of the most widely used game engines in the world, Unity provides easy-to-use and powerful game development tools, which undoubtedly attracts many developers to choose it to develop their own games. However, the tools needed in modern game development are not limited to game engines; other tools and services such as the cloud are increasingly used in game development. In this book, we will explore how to use the Unity game engine and the Microsoft Game Dev, including the Microsoft Azure Cloud and Microsoft Azure PlayFab services, to create games.
Starting by understanding the fundamentals of the Unity game engine, you will gradually become familiar with the Unity Editor and the key concepts of writing Unity scripts in C#, which will get you ready to make your own game.
Then, you'll learn how to work with Unity's built-in modules, such as the UI system, animation system, physics system, and how to integrate video and audio in your game to make your game more interesting.
As you progress through the chapters, I'll take you through advanced topics, such as the math involved in computer graphics, how to create post-processing effects in Unity with the new Scriptable Render Pipeline, how to use Unity's C# Job System to implement multithreading, and how to use Unity's Entity Component System (ECS) to write game logic code in a data-oriented way to improve game performance.
Along the way, you'll also learn about the Microsoft Game Dev, the Azure cloud services, Azure PlayFab, and using the Unity3D PlayFab SDK to access the PlayFab API to save and load data from the cloud.
By the end of this book, you'll be familiar with the Unity game engine, have a high-level understanding of the Azure cloud, and be ready to develop your own games.
Who this book is for
The book is for developers with intermediate .NET and C# programming experience who are interested in learning game development with Unity. Basic experience in C# programming is assumed.
What this book covers
Chapter 1, Hello Unity, explains the fundamentals of the Unity game engine. Beginning with the Unity installation process and then exploring the editor, you will also learn about .NET profiles and the scripting backend offered by Unity, and finally, you will have a broad understanding of Unity.
Chapter 2, Scripting Concepts in Unity, continues from the previous chapter and introduces scripting in Unity in detail. It begins by introducing the most commonly used classes in Unity scripting and then explains the life cycle of scripts. It also covers how to create a new script in Unity and attach a script as a component to a GameObject, and demonstrates how to add or remove packages through the Unity Package Manager.
Chapter 3, Developing UI with the Unity UI System, covers the different types of UI elements commonly used in Unity. Additionally, this chapter also discusses how to develop UI in Unity by using a Model View ViewModel (MVVM) architectural pattern. It ends by exploring some optimization tips for Unity UI.
Chapter 4, Creating Animations with the Unity Animation System, covers the most important concepts of the Unity animation system, such as animation clips, Animator Controller, Avatar, and the Animator component. Here, you will implement 3D and 2D animations using the animation system. It ends by exploring some optimization tips for the animation system in Unity.
Chapter 5, Working with the Unity Physics System, presents an overview of the physics solutions provided by Unity, including two built-in physics solutions, the NVIDIA PhysX engine and the Box2D engine. It also covers key concepts in the Unity physics system, such as Collider and Rigidbody. Here, you will implement a physics-based ping-pong game. It ends by exploring some optimization tips for the physics system in Unity.
Chapter 6, Integrating Audio and Video in a Unity Project, covers key concepts in the Unity audio system and video system, such as audio clip assets, Audio Source components, Audio Listener components, and Video Player components. It ends by exploring some optimization tips for the audio system in Unity.
Chapter 7, Understanding the Mathematics of Computer Graphics in Unity, covers the mathematics related to computer graphics, such as coordinate systems, vectors, matrices, and quaternions.
Chapter 8, The Scriptable Render Pipeline in Unity, presents an overview of three ready-made render pipelines to choose from in Unity, namely the legacy built-in render pipeline and two pre-made render pipelines based on the Scriptable Render Pipeline, the Universal Render Pipeline and the High Definition Render Pipeline. It also covers how to use the Universal Render Pipeline Asset to configure the render pipeline and how to use the Volume framework to apply post-processing effects to a game. It ends by exploring some optimization tips for the Universal Render Pipeline.
Chapter 9, Using Data-Oriented Technology Stack in Unity, covers what data-oriented design is and the difference between data-oriented design and traditional object-oriented design. It also explores the Data-Oriented Technology Stack (DOTS) in Unity and the three technology modules that make it up – namely, the C# Job System, ECS, and the Burst compiler.
Chapter 10, Serialization System and Assets Management in Unity and Azure, discusses binary serialization, YAML serialization, and JSON serialization in Unity. It also covers the assets workflow in Unity and ends by exploring how to create an Azure Blob storage service in the Azure cloud and load addressable content from Azure into a Unity project.
Chapter 11, Working with Microsoft Game Dev, Azure Cloud, PlayFab, and Unity, discusses what Microsoft Game Dev, Microsoft Azure Cloud, and Azure PlayFab are and why you should consider using them in game development. Here, you will implement the registration, login, and leaderboard functions in a Unity project through the API of Azure PlayFab.
To get the most out of this book
This book assumes that you have some familiarity with .NET and C#. This book covers basic concepts, advanced topics of the Unity game engine, and also other technologies such as the Microsoft Azure cloud and Azure PlayFab.
You'll also need a Long-Term Support (LTS) version of Unity installed on your computer – 2020 or later is recommended. You can find out how to install Unity on your computer in Chapter 1, Hello Unity. All code examples have been tested with Unity 2020.3.24 on a Windows OS. However, they should work with future version releases too.
You'll also need a Microsoft Azure cloud subscription, and you can apply for a free Azure account at the following link: https://azure.microsoft.com/en-in/free/.
If you wish to download sample projects from our GitHub repository, you will need a Git client; we recommend GitHub Desktop as it is the easiest to use. You can download it at the following link: https://desktop.github.com.
If you are using the Windows OS, you can also consider using Git for Windows. It can be downloaded at the following link: https://git-scm.com/download/win.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book's GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Game-Development-with-Unity-for-.NET-Developers. If there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781801078078_ColorImages.pdf.
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: If some content is generated at the beginning of the object collision via OnCollisionEnter, and you want to destroy them when the object collision ends, then you should consider using OnCollisionExit.
A block of code is set as follows:
using UnityEngine;
public class TriggerTest : MonoBehaviour
{
private void OnTriggerStay(Collider other)
{
Debug.Log(${this} stays {other}
);
}
}
}
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
using UnityEngine;
public class PingPongBall : MonoBehaviour
{
[SerializeField] private Rigidbody _rigidbody;
[SerializeField] private Vector3 _initialImpulse;
private void Start()
{
_rigidbody.AddForce(_initialImpulse,
ForceMode.Impulse);
}
}
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: Select 3D Object | Plane to create a new Plane object in the editor.
Tips or Important Notes
Appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Share Your Thoughts
Once you've read Game Development with Unity for .NET Developers, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.
Part 1: Basic Unity Concepts
In this section of the book, we'll explore the fundamentals of the Unity game engine and introduce some of the key concepts of scripting in Unity to get you ready to make your own games.
This section includes the following chapters:
Chapter 1, Hello Unity
Chapter 2, Scripting Concepts in Unity
Chapter 1: Hello Unity
Before we get started with using Unity to develop games, I think it's good to first understand Unity itself. Many people, especially those who are interested in games and game development, know that Unity is a widely used game engine, and you may have played many games developed with Unity. But you may not be familiar with how to use Unity to develop games. For example, there are many different Unity versions available, so how do you choose the version that suits you? Unity provides different subscription plans, but which subscription plan is right for your situation?
If you have never used Unity before, it is necessary for you to learn how to use the Unity Editor first. In addition to the Unity Editor, what features does the Unity engine provide to help game developers develop games? It is also important to know the features in Unity. If you are a .NET developer, then it's likely that you are familiar with Visual Studio. You need to know how to use Visual Studio to develop a Unity game. But developing a Unity game is different from developing a .NET application.
Am I asking too many questions? Don't worry – this chapter will help you answer them.
In this chapter, we will introduce how to choose the right release of Unity and provide an overview of how to download and install Unity via the Unity