Unity 2020 By Example
eBook - ePub

Unity 2020 By Example

A project-based guide to building 2D, 3D, augmented reality, and virtual reality games from scratch, 3rd Edition

Robert Wells

Share book
  1. 676 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Unity 2020 By Example

A project-based guide to building 2D, 3D, augmented reality, and virtual reality games from scratch, 3rd Edition

Robert Wells

Book details
Book preview
Table of contents
Citations

About This Book

Learn Unity game development with C# through a series of practical projects ranging from building a simple 2D game to adding AR/VR experiences and machine learning capabilities in a simple yet effective way

Key Features

  • Gain a high-level overview of the Unity game engine while building your own games portfolio
  • Discover best practices for implementing game animation, game physics, shaders, and effects
  • Create fully featured apps, including Space shooter and a 2D adventure game, and develop AR/VR experiences and Game AI agents

Book Description

The Unity game engine, used by millions of developers around the world, is popular thanks to its features that enable you to create games and 3D apps for desktop and mobile platforms in no time. With Unity 2020, this state-of-the-art game engine introduces enhancements in Unity tooling, editor, and workflow, among many other additions.

The third edition of this Unity book is updated to the new features in Unity 2020 and modern game development practices. Once you've quickly got to grips with the fundamentals of Unity game development, you'll create a collection, a twin-stick shooter, and a 2D adventure game. You'll then explore advanced topics such as machine learning, virtual reality, and augmented reality by building complete projects using the latest game tool kit. As you implement concepts in practice, this book will ensure that you come away with a clear understanding of Unity game development.

By the end of the book, you'll have a firm foundation in Unity development using C#, which can be applied to other engines and programming languages. You'll also be able to create several real-world projects to add to your professional game development portfolio.

What you will learn

  • Learn the fundamentals of game development, including GameObjects, components, and scenes
  • Develop a variety of games in C# and explore the brand new sprite shaping tool for Unity 3D and 2D games
  • Handle player controls and input functionality for your Unity games
  • Implement AI techniques such as pathfinding, finite state machines, and machine learning using Unity ML-Agents
  • Create virtual and augmented reality games using UnityVR and AR Foundation
  • Explore the cutting-edge features of Unity 2020 and how they can be used to improve your games

Who this book is for

If you are a game developer or programmer new to Unity and want to get up and running with the game engine in a hands-on way, this book is for you. Unity developers looking to work on practical projects to explore new features in Unity 2020 will find this book useful. A basic understanding of C# programming is required.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Unity 2020 By Example an online PDF/ePUB?
Yes, you can access Unity 2020 By Example by Robert Wells in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation de jeux. We have over one million books available in our catalogue for you to explore.

Information

Year
2020
ISBN
9781800200784

Chapter 1: Exploring the Fundamentals of Unity

Unity is a game engine that works with your existing asset pipeline (such as 3D modeling software) and can be used to compile video games that work seamlessly across multiple platforms and devices, including Windows, Mac, Linux, Android, and iOS. Using Unity, developers import ready-made assets (such as music, textures, and 3D models), and assemble them into a coherent whole, forming a game world that works according to a unified logic. This book focuses on developing games in Unity 2020 — taking you step by step through how to create increasingly complex projects.
This chapter starts the first project on our list, which will be a fun collection game. By the end of the next chapter, you'll have pieced together a simple but complete game. As part of the process, you'll become familiar with the fundamentals of developing in Unity, including the following:
  • New features in Unity 2020
  • Creating new projects using Unity Hub
  • How to navigate the Unity editor
  • Unity project structure
  • Importing assets using the Package Manager
  • Using the Unity editor to create a level
  • Creating optimized lighting effects
  • How to playtest the game
Using the information in this chapter, you will gain an understanding of how to create new projects from scratch, navigate the Unity editor, and import assets, information that will be invaluable for years to come as you develop your own projects in Unity.
Remember, it doesn't matter if you've never used Unity before. We'll go through everything that is required step by step, starting with the new features found in Unity 2020.

Technical requirements

This book is about Unity and developing games in that engine. The basics of programming as a subject is, however, beyond the scope of this book. So, I'll assume that you already have a working knowledge of coding generally but have not coded in Unity before.
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Unity-2020-By-Example.
Once downloaded, you can find the CollectionGame project in the Chapter01/End folder.

Exploring new features in Unity 2020

Before we start our first project, let's take a moment to look at the new features introduced since the previous edition of this book. We'll cover all of these, and much more!
Starting with Unity Hub, while not technically part of Unity 2020 (it is a separate application), it makes it easy to manage multiple Unity projects and versions. I will guide you through creating a new project using Unity Hub in this chapter. Once an empty project has been created, we will import assets using the new Package Manager — an easy way to manage a project's assets (more on this shortly).
In the world of 2D, a new tool called Sprite Shape will help us create more dynamic and flexible environments from within the Unity editor. Whether 2D or 3D, Artificial Intelligence (AI) is an ever-evolving field, and not to be left behind, Unity has introduced a new machine learning toolkit called ml-agents. This is an exciting new way to create intelligent agents (any dynamic non-playable character) in a game. Rather than defining exactly how an agent should act in every situation, we can provide the tools for the agent to learn how best to achieve their goals, whatever they may be.
It's an exciting time for Augmented Reality (AR), with the inclusion of ARFoundation in Unity, an AR toolkit, which we will use to blend reality and gaming. Lastly, we'll take a look at state of the art and investigate how we can optimize our games by using DOTs, a multi-threaded data-oriented technology stack. Don't worry if that sounds scary; it will all become clear as we progress through the book.
Now that we have an understanding of the some of the new topics covered in this book, let's design the first game we will implement in Unity 2020.

Introducing the first game

In the first game we will create, the player will control a character in the first person to explore an environment, collecting coins before a time limit runs out. If the timer runs out, the game is over. On the other hand, if all coins are collected before the timer expires, the player wins. The controls will use the industry-standard WASD keyboard setup, where W moves forward, A and S move left and right, and D walks backward. Head movement is controlled using the mouse, and coins are collected by colliding with them.
The benefit of developing this type of game is that it will demonstrate all the core Unity features, and we won't need to rely on any external software to make assets, such as textures, meshes, and materials.
See Figure 1.1, which features the coin collection game in action in the Unity Editor:
Figure 1.1 – The completed coin collection game
Figure 1.1 – The completed coin collection game
Important note
The completed CollectionGame project, as discussed in this chapter and the next, can be found in the book companion files in the Chapter02/End folder.
Now that we have an idea of the type of game we'll be making, in the next section, we can start development by creating the initial project structure.
Getting started with Unity
Every time you want to make a new Unity game, including coin collection games, you'll need to create a new project. Generally speaking, Unity uses the term project to mean a game. There are two main ways to make a new project, and it really doesn't matter which one you choose because both end up in the same place. If you're already in the Unity interface, looking at an existing scene or level, you can select File | New Project... from the application menu, as shown in Figure 1.2:
Figure 1.2 – Creating a new project via the main menu
Figure 1.2 – Creating a new project via the main menu
After selecting the New Project option, Unity leads you to the project creation wizard.
Alternatively, you can create a new project using Unity Hub, as shown in Figure 1.3. Unity Hub is a standalone application that you can use not only to manage your projects, but your Unity installations as well. So, if you want...

Table of contents