Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learning C# 7 By Developing Games with Unity 2017
Learning C# 7 By Developing Games with Unity 2017

Learning C# 7 By Developing Games with Unity 2017: Learn C# Programming by building fun and interactive games with Unity , Third Edition

Arrow left icon
Profile Icon DaGraça Profile Icon Grzegorz Lukosek
Arrow right icon
€22.99 €32.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6 (7 Ratings)
eBook Dec 2017 290 pages 3rd Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon DaGraça Profile Icon Grzegorz Lukosek
Arrow right icon
€22.99 €32.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6 (7 Ratings)
eBook Dec 2017 290 pages 3rd Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning C# 7 By Developing Games with Unity 2017

Introducing the Building Blocks for Unity Scripts

The C# programming language can appear to be very complicated at first, but in reality, there are two basic parts that form its foundation. These parts are variables and methods. Therefore, understanding these critical parts is necessary to learn any of the other features of C#. As critical as they are, they are very simple concepts to understand. Using these variable and method foundation pieces, we'll introduce the C# building blocks that are used to create Unity scripts.

For those who get sweaty palms just thinking of the word script, wipe your hands and relax! In this chapter, I'm going to use terms that are already familiar to you to introduce the building blocks of programming. The following are the concepts introduced in this chapter:

  • Using variables and methods in scripts
  • The class, which is a container for variables...

Understanding what a variable is and what it does

What is a variable? Technically, it's a tiny section of your computer's memory that will hold any information that you put there. While a game is running, it keeps track of where the information is stored, the value kept there, and the type of that value. However, for this chapter, all you need to know is how a variable works. It's very simple.

What's usually in a mailbox, besides air? Well usually there's nothing, but occasionally there is something in it. Sometimes, there are letters, bills, a spider, and so on. The point is that what is in a mailbox can vary. Therefore, let's call each mailbox a variable.

In the game development world, some simple examples of variables might be:

  • playerName
  • playerScore
  • highestScore
...

What is a method?

When we write a script, we are making lines of code that the computer is going to execute, one line at a time. As we write our code, there will be things that we want our game to execute more than once. For example, we can write a piece of code that adds two numbers. Suppose our game needs to add those two numbers a hundred different times during gameplay. So you'd say, "Wow! I have to write the same code a hundred times to add two numbers together? There has to be a better way."

Let a method take away your typing pain. You just have to write the code to add two numbers once and then give this chunk of code a name, such as AddTwoNumbers(). Now, every time your game needs to add two numbers, don't write the code over and over, just call the AddTwoNumbers() method.

...

Introducing the class

The class plays a major role in Unity. Most of your code will be written inside classes. Think of it like a container for variables and methods.

You just learned about variables and methods. These two items are the building blocks used in Unity scripts. The term "script" is used everywhere in discussions and documents. Look for it in the dictionary, and you will see that it can generally be described as written text. Sure enough, that's what we have. However, since we aren't just writing a screenplay or passing a note to someone, we need to learn the actual terms used in programming.

Unity calls the code it creates a C# script. However, people like me have to teach you some basic programming skills and tell you that a script is really a class.

In the previous section about methods, we created a class (script) called variableScript. It...

The Start(), Update(), and Awake() methods, and the execution order

The Start(), Update(), and Awake() methods are called automatically. The Start() method is called on the frame when the script is enabled. For most of our components, this will be when you press the Start button in Unity.

The Awake() method is called just before the Start() method. That gives a very convenient place to set up code if you have any. The Update() method is very specific. It's called on every frame if the component is enabled. It's very useful for observing user keyboard actions, for example. As you can see in our script, in Line 16 we are checking on every frame to find out whether the user has pressed the Enter key.

Let's create a new C# script and call it LearningMethods. As you can see, the Start() and Update() methods are added automatically when you create a new script. To...

Components that communicate using dot syntax

Our script has variables for holding data, and our script has methods to allow tasks to be performed. I now want to introduce the concept of communicating with other GameObjects and the components they contain. Communication between one component's GameObject and another component's GameObject using dot syntax is a vital part of scripting. It's what makes interaction possible. We need to communicate with other components or GameObjects to be able to use the variables and methods in other components.

What's with the dots?

When you look at code written by others, you'll see words with periods separating them. What the heck is that? It looks complicated...

Making decisions in code

The fundamental mechanism of programming is making decisions. In everyday life, we make hundreds and possibly thousands of decisions a day. They might be the results of simple questions such as "Do I need an umbrella today?" or "Should I drive at the maximum highway speed at the moment?" Let's first take a question and draw a single graph, as follows:

This is a fairly easy question. If it will be raining, I will need an umbrella; otherwise, I won't. In programming, we call it an if statement. It's a way we describe to the computer what code should be executed under what conditions. The question "Will it be raining?" is the condition. When planning your code, you should always break decisionmaking down into simple questions that can be answered only by a "yes" or a "no."

In C# syntax...

Understanding what a variable is and what it does


What is a variable? Technically, it's a tiny section of your computer's memory that will hold any information that you put there. While a game is running, it keeps track of where the information is stored, the value kept there, and the type of that value. However, for this chapter, all you need to know is how a variable works. It's very simple.

What's usually in a mailbox, besides air? Well usually there's nothing, but occasionally there is something in it. Sometimes, there are letters, bills, a spider, and so on. The point is that what is in a mailbox can vary. Therefore, let's call each mailbox a variable.

In the game development world, some simple examples of variables might be:

  • playerName
  • playerScore
  • highestScore

Naming a variable

Using the example of the mailbox, if I asked you to see what is in the mailbox, the first thing you'd ask is, "Which one?" If I say in the Smith mailbox, the brown mailbox, or the round mailbox, you'll know exactly...

What is a method?


When we write a script, we are making lines of code that the computer is going to execute, one line at a time. As we write our code, there will be things that we want our game to execute more than once. For example, we can write a piece of code that adds two numbers. Suppose our game needs to add those two numbers a hundred different times during gameplay. So you'd say, "Wow! I have to write the same code a hundred times to add two numbers together? There has to be a better way."

Let a method take away your typing pain. You just have to write the code to add two numbers once and then give this chunk of code a name, such as AddTwoNumbers(). Now, every time your game needs to add two numbers, don't write the code over and over, just call the AddTwoNumbers() method.

Using the term "method" instead of "function"

You are going to see the words "function" and "method" used everywhere as you learn how to code.

Note

The words "function" and "method" truly mean the same thing in Unity...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Learn the fundamentals of C# 7 scripting to develop GameObjects and master the basics of the new UI system in Unity 2017
  • • Build and develop your 2D game right from scratch and extend it to 3D while implementing the principles of object-oriented programming and coding in C# 7
  • • Get to grips with the fundamentals of optimizing your game using the latest features of Unity 2017

Description

Do you want to learn C# programming by creating fun and interactive games using the latest Unity 2017 platform? If so, look no further; this is the right book for you. Get started with programming C# so you can create 2D and 3D games in Unity. We will walk you through the basics to get you started with C# 7 and its latest features. Then, explore the use of C# 7 and its latest functional programming capabilities to create amazing games with Unity 2017. You will create your first C# script for Unity, add objects into it, and learn how to create game elements with it. Work with the latest functional programming features of C# and leverage them for great game scripting. Throughout the book, you will learn to use the new Unity 2017 2D tool set and create an interactive 2D game with it. You will make enemies appear to challenge your player, and discover some optimization techniques for great game performance. At the end, you will learn how to transform a 2D game into 3D, and you will be able to skill up to become a pro C# programmer with Unity 2017!

Who is this book for?

This book is for game developers and enthusiasts who want to get started with game development with Unity 2017. No prior experience of C# is required.

What you will learn

  • • Create your first 2D and 3D games in Unity
  • • Understand the fundamentals of variables, methods, and code syntax in C#
  • • Use loops and collections efficiently in Unity to reduce the amount of code
  • • Develop a game using object-oriented programming principles
  • • Implement simple enemy characters into the game to learn point-to-point movement and Tree behaviors
  • • Avoid performance mistakes by implementing different optimization techniques
  • • Export 3D models and animations and import them inside a Unity project

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2017
Length: 290 pages
Edition : 3rd
Language : English
ISBN-13 : 9781788399494
Vendor :
Unity Technologies
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 26, 2017
Length: 290 pages
Edition : 3rd
Language : English
ISBN-13 : 9781788399494
Vendor :
Unity Technologies
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
Unity 2017 Mobile Game Development
€36.99
Mastering Unity 2017 Game Development with C#
€41.99
Learning C# 7 By Developing Games with Unity 2017
€41.99
Total 120.97 Stars icon

Table of Contents

15 Chapters
Discovering Your Hidden Scripting Skills and Getting Your Environment Ready Chevron down icon Chevron up icon
Introducing the Building Blocks for Unity Scripts Chevron down icon Chevron up icon
Getting into the Details of Variables Chevron down icon Chevron up icon
Getting into the Details of Methods Chevron down icon Chevron up icon
Lists, Arrays, and Dictionaries Chevron down icon Chevron up icon
Loops Chevron down icon Chevron up icon
Object, a Container with Variables and Methods Chevron down icon Chevron up icon
Let's Make a Game! – from Idea to Development Chevron down icon Chevron up icon
Starting Your First Game Chevron down icon Chevron up icon
Writing GameManager Chevron down icon Chevron up icon
The Game Level Chevron down icon Chevron up icon
The User Interface Chevron down icon Chevron up icon
Collectables Chevron down icon Chevron up icon
Enemies Chevron down icon Chevron up icon
Audio, 3D Games, and Export Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6
(7 Ratings)
5 star 28.6%
4 star 42.9%
3 star 0%
2 star 14.3%
1 star 14.3%
Filter icon Filter
Top Reviews

Filter reviews by




L P. Feb 05, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Wow I just receive it I will review after I reading some chapters
Amazon Verified review Amazon
Hemunt Sharma Jan 12, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
this book is superb. helped me alot the only thing you guys need to know befor reading this book is to know some basic of Unity gaming Engine. Which is right this book is fully focused on coding used in Unity which is c# and over all this book is very good. And the files in the chapter 11 is on there website. go to there website search the name of book on there web site and download those file........ thank you.
Amazon Verified review Amazon
Justin Apr 25, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Does a great job of easing you into C# coding. Although I wish it tackled game design in unity earlier. Holds your hand well if you're terrified of coding.
Amazon Verified review Amazon
Vivek patel Jun 16, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Amazing book
Amazon Verified review Amazon
MarkFMB Feb 25, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good book for learning C# for Unity 2017. Covers both beginner and intermediate C# -- and explains C# within the context of Unity. Of note, the book's primary example is a 2D not a 3D game. The author explains that: "Creating 2D games is the best option for beginners and is why we primarily focused on 2D games throughout the book, although almost everything that we have created for 2D characters and platforms can be applied to 3D a well."I would encourage this author to create a follow-on book that would focus on 3D games -- and would take an intermediate C# Unity Script developer on to 3D.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.