Unity 5: Learning C# by Developing Games

Explore every nook and cranny of Unity 5 to turn your imaginations into reality

Unity 5: Learning C# by Developing Games

This ebook is included in a Mapt subscription
Greg Lukosek, John P. Doran, Chris Dickinson

6 customer reviews
Explore every nook and cranny of Unity 5 to turn your imaginations into reality
$10.00
RRP $69.99
eBook
Access every Packt eBook & Video for just $100
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Find Out More
 
Preview in Mapt

Book Details

ISBN 139781787127272
Paperback899 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, and adds a real-time global illumination to the games; and its powerful new features help to improve a game’s efficiency.

If you love games and want to learn how to make them but have no idea where to begin, then this course is built just for you. This learning path is divided into three modules which will take you in this incredible journey of creating games.

The course begins with getting you started with programming behaviors in C# so that you can create 2D games in Unity. You will begin by installing Unity and learning about its features. You will learn how to perform object-oriented programming and discover how to manage the game play loop, generate game levels, and develop a simple UI for the game. By the time this module comes to a close, you will have mastered the art of applying C# in Unity.

It is now time we put into use what we learned in the previous module into reality as we move onto the second module. Here, we will be building 7-8 action-packed games of different difficulty levels. Each project will focus on key Unity features as well as game strategy development. This module will mark your transformation from an application developer to a full-fledged Unity game developer.

Who wouldn’t love a game that is fully perfect, functional, and without any glitches? The third module deals with just that by teaching how to enhance your game by learning game optimization skills. Here, you’ll gain an understanding of possible solutions to any problem and how to implement them. You will then learn everything you need to know about where performance bottlenecks can be found, why they happen, and how to work around them.

With this massive wealth of knowledge, at the end of this learning path, you will be able to leverage an array of game development techniques to create your own basic games while resolving any issues that you encounter.

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
Chapter 14: 2D Twin-stick Shooter
Project overview
Setting up the project
Creating our scene
Implementing player movement
Shooting behavior
Creating enemies
Adding GameController to spawn enemy waves
Particle systems for enemy explosion
Adding in sound effects/music
Adding in points, score, and wave numbers
Publishing the game
Summary
Challenges
Chapter 15: Creating GUIs
Project overview
Creating the main menu level
Adding a header text object
Adding main menu buttons
Pausing the game
Restarting the game
Creating an Options menu
Summary
Challenges
Chapter 16: GUIs Part 2 – Clicker Game
Project overview
Starting our project
Recording and displaying clicks
Creating a shop
Opening/closing the shop
Purchasing upgrades
Summary
Challenges
Chapter 17: Mobile Endless Game – Procedural Content
Project overview
Prerequisites
Project setup
Adding the background
Adding a simple animated character
Making a repeating background
Working with sorting layers
Creating our player behaviour
Creating obstacles
Spawning obstacles at runtime
Game start and end behaviours
Keeping score
Summary
Challenges
Chapter 18: Shooting Gallery – Working with Animations and Tweens
Project overview
Prerequisites
Project setup
Creating the environment
Adding a target
Creating many targets
Creating waves of targets
Adding in a time limit
Adding in Score/High score
Summary
Project completed
Challenges
Chapter 19: Side-scrolling Platformer
Project overview
Tile-based level creation
Creating our player
Creating Collectibles
Keeping score
Winning the game
Summary
Challenges
Chapter 20: First Person Shooter Part 1 – Creating Exterior Environments
Project overview
Project setup
Introduction to terrain
Exterior environment – terrain
Adding color to our terrain – textures
Adding water
Adding trees
Adding in details – grass
Building atmosphere
Summary
Challenges
Chapter 21: First-person Shooter Part 2 – Creating Interior Environments
Project overview
Project setup
Importing assets
Creating tiles
Placing tiles with grid snapping
Creating and placing props
Lightmapping quickstart
Summary
Challenges
Chapter 22: First Person Shooter Part 3 – Implementing Gameplay and AI
Project overview
Setting up the project
Creating our player
Adding a flashlight
Creating our weapon
Creating an enemy
Enemy movement
Damaging and killing enemies
Using controller input
Moving to other levels
Summary
Challenges
Chapter 23: Building an In-Game Level Editor
Project overview
Level editor – introduction
Level editor – adding/removing walls at runtime
Level editor – toggling editor, GUI, and selecting additional tiles
Level editor – saving/loading levels to file
Summary
Challenges
Chapter 24: Finishing Touches
Project overview
Setting up the build settings
Customizing your exported project via the player settings
Building an installer for Windows
Summary
Challenges
Chapter 25: Detecting Performance Issues
The Unity Profiler
Best approaches to performance analysis
Targeted profiling of code segments
Saving and loading Profiler data
Final thoughts on Profiling and Analysis
Summary
Chapter 26: Scripting Strategies
Cache Component references
Obtaining Components using the fastest method
Removing empty callback declarations
Avoiding the Find() and SendMessage() methods at runtime
Disabling unused scripts and objects
Consider using distance-squared over distance
Avoid retrieving string properties from GameObjects
Update, Coroutines, and InvokeRepeating
Consider caching Transform changes
Faster GameObject null reference checks
Summary
Chapter 27: The Benefits of Batching
Draw Calls
Materials and Shaders
Dynamic Batching
Static Batching
Summary
Chapter 28: Kickstart Your Art
Audio
Texture files
Mesh and animation files
Summary
Chapter 29: Faster Physics
Physics Engine internals
Physics performance optimizations
Summary
Chapter 30: Dynamic Graphics
Profiling rendering issues
Front end bottlenecks
Back end bottlenecks
Lighting and Shadowing
Optimizing graphics for mobile
Summary
Chapter 31: Masterful Memory Management
The Mono platform
Memory usage optimization
Prefab pooling
The future of Mono and Unity
Summary
Chapter 32: Tactical Tips and Tricks
Editor hotkey tips
Editor interface tips
Scripting tips
Custom editors/menus tips
External tips
Summary

What You Will Learn

  • Master the art of applying C# in Unity. 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.
  • Create and code a good-looking functional UI system for your game.
  • Find out how to create exciting and interactive games using GUIs.
  • Work with different animation assets and components to enhance your game further.
  • Personalize your game by learning how to use Unity’s advanced animation system.
  • Create, visualize, and edit animated creatures to add to your already amazing game.
  • Familiarize yourself with the tools and practices of game development Discover how to create the Game Manager class to, generate game levels, and develop UI for the game.
  • Use the Unity Profiler to find bottlenecks anywhere in your application, and discover how to resolve them.
  • Implement best practices for C# scripting to avoid common mistakes

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
Chapter 14: 2D Twin-stick Shooter
Project overview
Setting up the project
Creating our scene
Implementing player movement
Shooting behavior
Creating enemies
Adding GameController to spawn enemy waves
Particle systems for enemy explosion
Adding in sound effects/music
Adding in points, score, and wave numbers
Publishing the game
Summary
Challenges
Chapter 15: Creating GUIs
Project overview
Creating the main menu level
Adding a header text object
Adding main menu buttons
Pausing the game
Restarting the game
Creating an Options menu
Summary
Challenges
Chapter 16: GUIs Part 2 – Clicker Game
Project overview
Starting our project
Recording and displaying clicks
Creating a shop
Opening/closing the shop
Purchasing upgrades
Summary
Challenges
Chapter 17: Mobile Endless Game – Procedural Content
Project overview
Prerequisites
Project setup
Adding the background
Adding a simple animated character
Making a repeating background
Working with sorting layers
Creating our player behaviour
Creating obstacles
Spawning obstacles at runtime
Game start and end behaviours
Keeping score
Summary
Challenges
Chapter 18: Shooting Gallery – Working with Animations and Tweens
Project overview
Prerequisites
Project setup
Creating the environment
Adding a target
Creating many targets
Creating waves of targets
Adding in a time limit
Adding in Score/High score
Summary
Project completed
Challenges
Chapter 19: Side-scrolling Platformer
Project overview
Tile-based level creation
Creating our player
Creating Collectibles
Keeping score
Winning the game
Summary
Challenges
Chapter 20: First Person Shooter Part 1 – Creating Exterior Environments
Project overview
Project setup
Introduction to terrain
Exterior environment – terrain
Adding color to our terrain – textures
Adding water
Adding trees
Adding in details – grass
Building atmosphere
Summary
Challenges
Chapter 21: First-person Shooter Part 2 – Creating Interior Environments
Project overview
Project setup
Importing assets
Creating tiles
Placing tiles with grid snapping
Creating and placing props
Lightmapping quickstart
Summary
Challenges
Chapter 22: First Person Shooter Part 3 – Implementing Gameplay and AI
Project overview
Setting up the project
Creating our player
Adding a flashlight
Creating our weapon
Creating an enemy
Enemy movement
Damaging and killing enemies
Using controller input
Moving to other levels
Summary
Challenges
Chapter 23: Building an In-Game Level Editor
Project overview
Level editor – introduction
Level editor – adding/removing walls at runtime
Level editor – toggling editor, GUI, and selecting additional tiles
Level editor – saving/loading levels to file
Summary
Challenges
Chapter 24: Finishing Touches
Project overview
Setting up the build settings
Customizing your exported project via the player settings
Building an installer for Windows
Summary
Challenges
Chapter 25: Detecting Performance Issues
The Unity Profiler
Best approaches to performance analysis
Targeted profiling of code segments
Saving and loading Profiler data
Final thoughts on Profiling and Analysis
Summary
Chapter 26: Scripting Strategies
Cache Component references
Obtaining Components using the fastest method
Removing empty callback declarations
Avoiding the Find() and SendMessage() methods at runtime
Disabling unused scripts and objects
Consider using distance-squared over distance
Avoid retrieving string properties from GameObjects
Update, Coroutines, and InvokeRepeating
Consider caching Transform changes
Faster GameObject null reference checks
Summary
Chapter 27: The Benefits of Batching
Draw Calls
Materials and Shaders
Dynamic Batching
Static Batching
Summary
Chapter 28: Kickstart Your Art
Audio
Texture files
Mesh and animation files
Summary
Chapter 29: Faster Physics
Physics Engine internals
Physics performance optimizations
Summary
Chapter 30: Dynamic Graphics
Profiling rendering issues
Front end bottlenecks
Back end bottlenecks
Lighting and Shadowing
Optimizing graphics for mobile
Summary
Chapter 31: Masterful Memory Management
The Mono platform
Memory usage optimization
Prefab pooling
The future of Mono and Unity
Summary
Chapter 32: Tactical Tips and Tricks
Editor hotkey tips
Editor interface tips
Scripting tips
Custom editors/menus tips
External tips
Summary

Book Details

ISBN 139781787127272
Paperback899 pages
Read More
From 6 reviews

Read More Reviews