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

Partager le livre
  1. 428 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
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

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

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.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Learning C# by Developing Games with Unity 2021 est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Learning C# by Developing Games with Unity 2021 par Harrison Ferrone en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming in C#. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2021
ISBN
9781801812962
Édition
6

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...

Table des matiĂšres