Unity From Zero to proficiency (Beginner)
Third Edition
A step-by-step guide to coding your first game.
Patrick Felicia
Unity From Zero to Proficiency
(Beginner)
Copyright 2020 Patrick Felicia
All rights reserved. No part of this book may be reproduced, stored in retrieval systems, or transmitted in any form or by any means, without the prior written permission of the publisher (Patrick Felicia), 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 expressed or implied. Neither the author and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
First published: December 2015
Second Edition published: February 2018
Third Edition published: March 2019
Fourth Edition published: March 2020
P ublished by Patrick Felicia
Credits
Author: Patrick Felicia
About the Author
Patrick Felicia is a lecturer and researcher at Waterford Institute of Technology, where he teaches and supervises undergraduate and postgraduate students. He obtained his MSc in Multimedia Technology in 2003 and PhD in Computer Science in 2009 from University College Cork, Ireland. He has published several books and articles on the use of video games for educational purposes, including the Handbook of Research on Improving Learning and Motivation through Educational Games: Multidisciplinary Approaches (published by IGI), and Digital Games in Schools: A Handbook for Teachers, published by European Schoolnet. Patrick is also the Editor-in-chief of the International Journal of Game-Based Learning (IJGBL), and the Conference Director of the Irish Symposium on Game-Based Learning, a popular conference on games and learning organized throughout Ireland.
Support and Resources for this Book + Free Book
As a new reader of my book series, and to thank you for choosing this book, I would like to offer you a free book. So, to receive your book, just email me at with a screenshot of your receipt and I will send you a copy of the book A Quick Guide to Artificial Intelligence , a book that will extend the content provided in this book and help you to create and include NPCs with Artificial Intelligence. After receiving your free book, you will also receive weekly updates and FREE tutorials on Unity.
To complete the activities presented in this book you need to download the startup pack on the companion website; it consists of free resources that you will need to complete your projects, including bonus material that will help you along the way (e.g., cheat sheets, introductory videos, code samples, and much more).
Amongst other things, the resources for this book include:
- All the C# scripts used in this book.
- Cheat sheets with tips on how to use Unity.
- 3D characters and animations that you can use in Unity.
- A library of over 40 tutorials (video or text).
To download these resources, please do the following:
- Open the following link: http://learntocreategames.com/books/
- Select this book ( Unity from Zero to Proficiency - Beginner ).
- On the new page, click on the link labelled Book Files , or scroll down to the bottom of the page.
- In the section called Download your Free Resource Pack , enter your email address and your first name, and click on the button labeled Yes, I want to receive my bonus pack .
- After a few seconds, you should receive a link to your free start-up pack.
- When you receive the link, you can download all the resources to your computer.
This book is dedicated to Helena & Mathis
[ ]
Table of Contents
Chapter 1: Introduction to Programming in C#
Introduction
Statements
Comments
Variables
Arrays
Constants
Operators
Conditional statements
Switch statements
Loops
Classes
Defining a class
Accessing class members and variables
Constructors
Destructors
Static members of a class
Inheritance
Methods
Accessing methods and access modifiers
Common methods
Scope of variables
Events
Polymorphism (general concepts)
Dynamic polymorphism
Workflow to create a script
How scripts are compiled
Coding convention
A few things to remember when you create a script (checklist)
Level roundup
Chapter 2: Creating your First Script
Quick overview of the interface
Getting started
Creating your first method
Creating your own class
Common errors and their meaning
Best practices
Level roundup
Chapter 3: Adding Interaction with C#
Resources necessary for this chapter
Creating a simple script to collect objects
Adding a scoring system
Loading a new level based on the score
Level roundup
Chapter 4: Creating and Updating a User Interface from Your Code
Creating a timer
Collecting boxes and displaying messages accordingly
Deleting the user messages after a few seconds
Rotating objects to be picked-up
Collecting petrol cans on the island
Level roundup
Chapter 5: Polishing Our Game
Creating a splash-screen for the game
Displaying the score in each scene
Displaying items collected as part of the user interface (using images)
Adding sound effects
Playing a background music
Adding a mini-map
Level roundup
Chapter 6: Adding and Managing Simple Artificial Intelligence
Adding and setting-up our first NPC
Creating a path for our NPC
Detecting collision between the NPC and the player.
Level roundup
Chapter 7: Creating a Word Guessing Game
Creating the interface for the game
Detecting and processing the user input
Choosing random words
Tracking the score and the number of attempts
Choosing words from a file
Level roundup
Chapter 8: Creating an Infinite Runner
Adding movement to the character
Adding random obstacles to the scene
Displaying the score
Improving the appearance of the game
Creating the static environment
Pausing the game
Level roundup
Chapter 9: Frequently Asked Questions
Scripts
Interaction with assets
Using a graphical user interface
Audio
Artificial intelligence
Accessing Resources
Detecting user inputs
Thank you
Preface
Learning to code and to create your first game can seem daunting; but I can guarantee you that after completing this book, you will have a solid understanding of C# concepts and you will also be able to start creating your own game with many of the core features found in 3D survival games, including collisions, menus, and navigation. You can do this!
After teaching Unity for over 4 years, I always thought it could be great to find a book that could get my students started with Unity in a few hours and that showed them how to master the core functionalities offered by this fantastic software.
Many of the books that I found were too short and did not provide enough details on the why behind the actions recommended and taken; other books were highly theoretical, and I found that they lacked practicality and that they would not get my students full attention. In addition, I often found that game development may be preferred by those with a programming background but that those with an Arts background, even if they wanted to get to know how to create games, often had to face the issue of learning to code for the first time.
Next page