Learning C# by Developing Games with Unity 5.x - Second Edition

Develop your first interactive 2D platformer game by learning the fundamentals of C#

Learning C# by Developing Games with Unity 5.x - Second Edition

Greg Lukosek

3 customer reviews
Develop your first interactive 2D platformer game by learning the fundamentals of C#
Mapt Subscription
FREE
$29.99/m after trial
eBook
$25.20
RRP $35.99
Print + eBook
$44.99
RRP $44.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$25.20
$44.99
$29.99p/m after trial
RRP $35.99
RRP $44.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781785287596
Paperback230 pages

Book Description

Unity is a cross-platform game engine that is used to develop 2D and 3D video games. Unity 5 is the latest version, released in March 2015, and adds a real-time global illumination to the games, and its powerful new features help to improve a game’s efficiency.

This book will get you started with programming behaviors in C# so you can create 2D games in Unity. You will begin by installing Unity and learning about its features, followed by creating a C# script. We will then deal with topics such as unity scripting for you to understand how codes work so you can create and use C# variables and methods. Moving forward, you will find out how to create, store, and retrieve data from collection of objects.

You will also develop an understanding of loops and their use, and you’ll perform object-oriented programming. This will help you to turn your idea into a ready-to-code project and set up a Unity project for production. Finally, you will discover how to create the GameManager class to manage the game play loop, generate game levels, and develop a simple UI for the game.

By the end of this book, you will have mastered the art of applying C# in Unity.

Table of Contents

Chapter 1: Discovering Your Hidden Scripting Skills and Getting Your Environment Ready
Prerequisite knowledge to use this book
Dealing with scriptphobia
Downloading Unity
Teaching behavior to GameObjects
C# documentation – where to find it? Do I need it at all?
Working with C# script files
Creating a C# script file
Introducing the MonoDevelop code editor
Instance? What is it?
Summary
Chapter 2: Introducing the Building Blocks for Unity Scripts
Understanding what a variable is and what it does
What is a method?
Introducing the class
The Start(), Update(), and Awake() methods and the execution order
Components that communicate using dot syntax
Making decisions in code
Paper and pencil are powerful tools

Summary
Chapter 3: Getting into the Details of Variables
Writing C# statements properly
Understanding component properties in Unity's Inspector
Changing a property's value in the Inspector panel
Private variables
Naming your variables properly
Beginning variable names with lowercase
Using multiword variable names
Declaring a variable and its type
Assigning values while declaring a variable
Where you declare a variable is important
Variable scope – determining where a variable can be used
Summary
Chapter 4: Getting into the Details of Methods
Using methods in a script
Naming methods properly
Defining a method the right way
Understanding parentheses – why are they there?
Specifying a method's parameters
Returning a value from a method
Summary
Chapter 5: Lists, Arrays, and Dictionaries
What is an array?
Storing items in the List
List<T> versus arrays
Retrieving the data from the Array or List<T>
ArrayList
Dictionaries
Summary
Chapter 6: Loops
Introduction to loops
The foreach loop
The for loop
The while loop
while versus for loops
Loops in statements
Modulo
Searching for data inside an array
Breaking the loop
Summary
Chapter 7: Object, a Container with Variables and Methods
Working with objects is a class act
Instantiating an object
Bored yet?
Using methods with objects
Custom constructors
Overloading
Summary
Chapter 8: Let's Make a Game! – From Idea to Development
Your first game – avoiding the trap of the never-ending concept
The idea
Breaking a complex idea into smaller parts
Jake on the mysterious planet – the feature list
Target platform and resolution
Target screen resolution
Summary
Chapter 9: Starting Your First Game
Setting up a new Unity project for our game
Preparing the player prefab
PlayerController
User input
Animator
Code
Summary
Chapter 10: Writing GameManager
Gameplay loops
Singleton class
Starting the game
Setting up input keys
Using triggers
Restarting the game
Setting up the player starting position
Code in this chapter
Summary
Chapter 11: The Game Level
Generating levels versus designed levels
Creating a copy of the level piece
Instantiating
Vector3
Testing LevelGenerator
Extending the level
The code used in this chapter
Summary
Chapter 12: The User Interface
Introducting the Unity UI
Views
Buttons
Hiding and showing the Canvas
Reference exceptions
GameView
The code in this chapter
Summary
Chapter 13: Collectables — What Next?
Collectables
The coin prefab
High score and persisting data
The Update function and UI values
What next?
The code in this chapter
Summary

What You Will Learn

  • Understand the fundamentals of variables, methods, and code syntax in C#
  • Get to know about techniques to turn your game idea into working project
  • Use loops and collections efficiently in Unity to reduce the amount of code
  • Develop a game using the object-oriented programming principles
  • Generate infinite levels for your game
  • Create and code a good-looking functional UI system for your game
  • Publish and share your game with users

Authors

Table of Contents

Chapter 1: Discovering Your Hidden Scripting Skills and Getting Your Environment Ready
Prerequisite knowledge to use this book
Dealing with scriptphobia
Downloading Unity
Teaching behavior to GameObjects
C# documentation – where to find it? Do I need it at all?
Working with C# script files
Creating a C# script file
Introducing the MonoDevelop code editor
Instance? What is it?
Summary
Chapter 2: Introducing the Building Blocks for Unity Scripts
Understanding what a variable is and what it does
What is a method?
Introducing the class
The Start(), Update(), and Awake() methods and the execution order
Components that communicate using dot syntax
Making decisions in code
Paper and pencil are powerful tools

Summary
Chapter 3: Getting into the Details of Variables
Writing C# statements properly
Understanding component properties in Unity's Inspector
Changing a property's value in the Inspector panel
Private variables
Naming your variables properly
Beginning variable names with lowercase
Using multiword variable names
Declaring a variable and its type
Assigning values while declaring a variable
Where you declare a variable is important
Variable scope – determining where a variable can be used
Summary
Chapter 4: Getting into the Details of Methods
Using methods in a script
Naming methods properly
Defining a method the right way
Understanding parentheses – why are they there?
Specifying a method's parameters
Returning a value from a method
Summary
Chapter 5: Lists, Arrays, and Dictionaries
What is an array?
Storing items in the List
List<T> versus arrays
Retrieving the data from the Array or List<T>
ArrayList
Dictionaries
Summary
Chapter 6: Loops
Introduction to loops
The foreach loop
The for loop
The while loop
while versus for loops
Loops in statements
Modulo
Searching for data inside an array
Breaking the loop
Summary
Chapter 7: Object, a Container with Variables and Methods
Working with objects is a class act
Instantiating an object
Bored yet?
Using methods with objects
Custom constructors
Overloading
Summary
Chapter 8: Let's Make a Game! – From Idea to Development
Your first game – avoiding the trap of the never-ending concept
The idea
Breaking a complex idea into smaller parts
Jake on the mysterious planet – the feature list
Target platform and resolution
Target screen resolution
Summary
Chapter 9: Starting Your First Game
Setting up a new Unity project for our game
Preparing the player prefab
PlayerController
User input
Animator
Code
Summary
Chapter 10: Writing GameManager
Gameplay loops
Singleton class
Starting the game
Setting up input keys
Using triggers
Restarting the game
Setting up the player starting position
Code in this chapter
Summary
Chapter 11: The Game Level
Generating levels versus designed levels
Creating a copy of the level piece
Instantiating
Vector3
Testing LevelGenerator
Extending the level
The code used in this chapter
Summary
Chapter 12: The User Interface
Introducting the Unity UI
Views
Buttons
Hiding and showing the Canvas
Reference exceptions
GameView
The code in this chapter
Summary
Chapter 13: Collectables — What Next?
Collectables
The coin prefab
High score and persisting data
The Update function and UI values
What next?
The code in this chapter
Summary

Book Details

ISBN 139781785287596
Paperback230 pages
Read More
From 3 reviews

Read More Reviews