Learning C# by Developing Games with Unity 2021
eBook - ePub

Learning C# by Developing Games with Unity 2021

Kickstart your C# programming and Unity journey by building 3D games from scratch, 6th Edition

Harrison Ferrone

Buch teilen
  1. 428 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Learning C# by Developing Games with Unity 2021

Kickstart your C# programming and Unity journey by building 3D games from scratch, 6th Edition

Harrison Ferrone

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Learn C# programming from scratch using Unity as a fun and accessible entry point with this updated edition of the bestselling series. Includes invitation to join the online Unity Game Development community to read the book alongside peers, Unity developers/C# programmers and Harrison Ferrone.

Purchase of the print or Kindle book includes a free eBook in the PDF format.

Key Features

  • Learn C# programming basics, terminology, and coding best practices
  • Become confident with Unity fundamentals and features in line with Unity 2021
  • Apply your C# knowledge in practice and build a working first-person shooter game prototype in Unity

Book Description

The Learning C# by Developing Games with Unity series has established itself as a popular choice for getting up to speed with C#, a powerful and versatile programming language with a wide array of applications in various domains. This bestselling franchise presents a clear path for learning C# programming from the ground up through the world of Unity game development.

This sixth edition has been updated to introduce modern C# features with Unity 2021. A new chapter has also been added that covers reading and writing binary data from files, which will help you become proficient in handling errors and asynchronous operations.

The book acquaints you with the core concepts of programming in C#, including variables, classes, and object-oriented programming. You will explore the fundamentals of Unity game development, including game design, lighting basics, player movement, camera controls, and collisions. You will write C# scripts for simple game mechanics, perform procedural programming, and add complexity to your games by introducing smart enemies and damage-causing projectiles.

By the end of the book, you will have developed the skills to become proficient in C# programming and built a playable game prototype with the Unity game engine.

What you will learn

  • Follow simple steps and examples to create and implement C# scripts in Unity
  • Develop a 3D mindset to build games that come to life
  • Create basic game mechanics such as player controllers and shooting projectiles using C#
  • Divide your code into pluggable building blocks using interfaces, abstract classes, and class extensions
  • Become familiar with stacks, queues, exceptions, error handling, and other core C# concepts
  • Learn how to handle text, XML, and JSON data to save and load your game data
  • Explore the basics of AI for games and implement them to control enemy behavior

Who this book is for

If you're a developer, programmer, hobbyist, or anyone who wants to get started with Unity and C# programming in a fun and engaging manner, this book is for you. You'll still be able to follow along if you don't have programming experience, but knowing the basics will help you get the most out of this book.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Learning C# by Developing Games with Unity 2021 als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Learning C# by Developing Games with Unity 2021 von Harrison Ferrone im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming in C#. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2021
ISBN
9781801812962

4

Control Flow and Collection Types

One of the central duties of a computer is to control what happens when predetermined conditions are met. When you click on a folder, you expect it to open; when you type on the keyboard, you expect the text to mirror your keystrokes. Writing code for applications or games is no different—they both need to behave in a certain way in one state, and in another when conditions change. In programming terms, this is called control flow, which is apt because it controls the flow of how code is executed in different scenarios.
In addition to working with control statements, we'll be taking a hands-on look at collection data types. Collections are a category of types that allow multiple values, and groupings of values, to be stored in a single variable. We'll break the chapter down into the following topics:
  • Selection statements
  • Working with array, dictionary, and list collections
  • Iteration statements with for, foreach, and while loops
  • Fixing infinite loops

Selection statements

The most complex programming problems can often be boiled down to sets of simple choices that a game or program evaluates and acts on. Since Visual Studio and Unity can't make those choices by themselves, writing out those decisions is up to us.
The if-else and switch selection statements allow you to specify branching paths, based on one or more conditions, and the actions you want to be taken in each case. Traditionally, these conditions include the following:
  • Detecting user input
  • Evaluating expressions and Boolean logic
  • Comparing variables or literal values
You're going to start with the simplest of these conditional statements, if-else, in the following section.

The if-else statement

if-else statements are the most common way of making decisions in code. When stripped of all its syntax, the basic idea is, If my condition is met, execute this block of code; if it's not, execute this other block of code. Think of these statements as gates, or doors, with the conditions as their keys. To pass through, the key needs to be valid. Otherwise, entry will be denied and the code will be sent to the next possible gate. Let's take a look at the syntax for declaring one of these gates.
A valid if-else statement requires the following:
  • The if keyword at the beginning of the line
  • A pair of parentheses to hold the condition
  • A statement body inside curly brackets
It looks like this:
if(condition is true) { Execute code of code } 
Optionally, an else statement can be added to store the action you want to take when the if statement condition fails. The same rules apply for the else statement:
else Execute single line of code // OR else { Execute multiple lines of code } 
In blueprint form, the syntax almost reads like a sentence, which is why this is the recommended approach:
if(condition is true) { Execute this code block } else { Execute this code block } 
Since these are great introductions to logical thinking, at least in programming, we'll break down the three different if-else variations in more detail:
  1. A single if statement can exist by itself in cases where you don't care about what happens if the condition isn't met. In the following example, if hasDungeonKey is set to true, then a debug log will print out; if set to false, no code will execute:
    public class LearningCurve: MonoBehaviour { public bool hasDungeonKey = true; Void Start() { if(hasDungeonKey) { Debug.Log("You possess the sacred key – enter."); } } } 
    When referring to a condition as being met, I mean that it evaluates to true, which is often referred to as a passing condition.
  2. Add an else s...

Inhaltsverzeichnis