Learning C by Developing Games With Unity 5 X Develop Your First Interactive 2D Platformer Game by Learning The Fundamentals of C Second Edition Greg Lukosek Instant Download
Learning C by Developing Games With Unity 5 X Develop Your First Interactive 2D Platformer Game by Learning The Fundamentals of C Second Edition Greg Lukosek Instant Download
https://textbookfull.com/product/learning-c-by-developing-games-
with-unity-5-x-develop-your-first-interactive-2d-platformer-game-
by-learning-the-fundamentals-of-c-second-edition-greg-lukosek-2/
https://textbookfull.com/product/learning-c-7-by-developing-
games-with-unity-2017-learn-c-programming-by-building-fun-and-
interactive-games-with-unity-third-edition-micael-dagraca/
https://textbookfull.com/product/developing-2d-games-with-unity-
independent-game-programming-with-c-1st-edition-jared-halpern/
https://textbookfull.com/product/developing-2d-games-with-unity-
independent-game-programming-with-c-1st-edition-jared-halpern-2/
Learning C by developing games with Unity 2020 An
enjoyable and intuitive approach to getting started
with C programming and Unity Fifth Edition Harrison
Ferrone
https://textbookfull.com/product/learning-c-by-developing-games-
with-unity-2020-an-enjoyable-and-intuitive-approach-to-getting-
started-with-c-programming-and-unity-fifth-edition-harrison-
ferrone/
https://textbookfull.com/product/learning-c-by-programming-
games-2nd-edition-wouter-van-toll/
https://textbookfull.com/product/learning-c-programming-with-
unity-3d-alex-okita/
https://textbookfull.com/product/hands-on-game-development-
patterns-with-unity-2019-create-engaging-games-by-using-industry-
standard-design-patterns-with-c-1st-edition-david-baron/
https://textbookfull.com/product/learning-unreal-engine-game-
development-a-step-by-step-guide-that-paves-the-way-for-
developing-fantastic-games-with-unreal-engine-4-1st-edition-
Table of Contents
Learning C# by Developing Games with Unity 5.x Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Discovering Your Hidden Scripting Skills and Getting Your
Environment Ready
Prerequisite knowledge to use this book
Dealing with scriptphobia
Downloading Unity
Obtaining a free license
Teaching behavior to GameObjects
Using Unity's documentation
Do I need to know all that?
C# documentation – where to find it? Do I need it at all?
The Unity community – asking others for help
Working with C# script files
Lots of files can create a mess
Why does my Project tab look different?
Creating a C# script file
Introducing the MonoDevelop code editor
Syncing C# files between MonoDevelop and Unity
Opening LearningScript in MonoDevelop
The namespace – highlighted in blue
The class definition – highlighted in green
Watching for possible gotchas while creating script files in Unity
Fixing synchronization if it isn't working properly
Adding our script to GameObject
Instance? What is it?
Summary
2. Introducing the Building Blocks for Unity Scripts
Understanding what a variable is and what it does
Naming a variable
A variable name is just a substitute for a value
Creating a variable and seeing how it works
Declaration
Assignment
Click on Play!
Changing variables
Watching for a possible gotcha when using public variables
What is a method?
Using the term "method" instead of "function"
Method names are substitutes, too
Introducing the class
Inheritance
The Start(), Update(), and Awake() methods and the execution
order
Components that communicate using dot syntax
What's with the dots?
Making decisions in code
Using the NOT operator to change the condition
Checking many conditions in an if statement
Using else if to make complex decisions
Making decisions based on user input
Paper and pencil are powerful tools
Summary
3. Getting into the Details of Variables
Writing C# statements properly
Understanding component properties in Unity's Inspector
Variables become component properties
Unity changes script and variable names slightly
Changing a property's value in the Inspector panel
Displaying public variables 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
The most common built-in variable types
Assigning values while declaring a variable
Where you declare a variable is important
Variable scope – determining where a variable can be used
Summary
4. Getting into the Details of Methods
Using methods in a script
Naming methods properly
Beginning method names with an uppercase letter
Using multiword names for a method
Parentheses are part of the method's name
Defining a method the right way
The minimum requirements for defining a method
Understanding parentheses – why are they there?
Specifying a method's parameters
How many parameters can a method have?
Returning a value from a method
Returning the value
Example
Summary
5. Lists, Arrays, and Dictionaries
What is an array?
Declaring an array
Storing items in the List
Common operations with Lists
List<T> versus arrays
Retrieving the data from the Array or List<T>
Checking the size
ArrayList
Dictionaries
Accessing values
How do I know what's inside my Hashtable?
Summary
6. Loops
Introduction to loops
The foreach loop
The for loop
An example
The while loop
while versus for loops
Loops in statements
Modulo
Searching for data inside an array
Breaking the loop
Summary
7. Object, a Container with Variables and Methods
Working with objects is a class act
Few facts
Example
Instantiating an object
Bored yet?
Using methods with objects
Custom constructors
Overloading
Summary
8. Let's Make a Game! – From Idea to Development
Your first game – avoiding the trap of the never-ending concept
The idea
Game mechanics and core components
Breaking a complex idea into smaller parts
Jake on the mysterious planet – the feature list
Procedural level generation
An animated 2D character
Physics
Mouse and touch controls
Collectables and obstacles
Scoring
UI – the user interface
Target platform and resolution
Target screen resolution
Summary
9. Starting Your First Game
Setting up a new Unity project for our game
Backup
Keeping your project clean
Preparing the player prefab
Rigidbody2D
CircleCollider2D
PlayerController
User input
Jump
Animator
Running
Code
PlayerController.cs
Summary
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
11. The Game Level
Generating levels versus designed levels
Creating a level chunk
Planning the LevelGenerator class
Writing LevelGenerator
Commenting on your code
Creating a copy of the level piece
Instantiating
Vector3
Testing LevelGenerator
Extending the level
The code used in this chapter
Summary
12. The User Interface
Introducting the Unity UI
Views
Constructing the view UI – how to keep things clean
Target screen resolution
Recognizing events
Buttons
A simple button
Image
The Button component
Interaction
The Button action
Hiding and showing the Canvas
Reference exceptions
GameView
Game Over
The code in this chapter
Summary
13. Collectables — What Next?
Collectables
The coin prefab
The Collectable class
High score and persisting data
The Update function and UI values
What next?
The code in this chapter
Summary
Index
Learning C# by Developing
Games with Unity 5.x Second
Edition
Learning C# by Developing
Games with Unity 5.x Second
Edition
Copyright © 2016 Packt Publishing
Every effort has been made in the preparation of this book to ensure
the accuracy of the information presented. However, the information
contained in this book is sold without warranty, either express or
implied. Neither the author, nor Packt Publishing, and its dealers and
distributors will be held liable for any damages caused or alleged to
be caused directly or indirectly by this book.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-759-6
www.packtpub.com
Credits
Author
Greg Lukosek
Terry Norton
Reviewer
Karl Henkel
Commissioning Editor
Ashwin Nair
Acquisition Editor
Vinay Argekar
Deepti Thore
Technical Editor
Mohita Vyas
Copy Editor
Vikrant Phadke
Project Coordinator
Shweta H Birwatkar
Proofreader
Safis Editing
Indexer
Mariammal Chettiyar
Graphics
Disha Haria
Production Coordinator
Nilesh Mohite
Cover Work
Nilesh Mohite
About the Author
Greg Lukosek was born and raised in the Upper Silesia region of
Poland. When he was about 8 years old, his amazing parents bought
him and his brother a Commodore C64. That was when his love of
programming started. He would spend hours writing simple basic
code, and when he couldn't write it on the computer directly, he
used a notepad.
Greg met the love of his life, Kasia, in 2003, which changed his life
forever. They both moved to London in search of adventure and
decided to stay there.
His love for programming overcomes his love for 3D graphics. Greg
ditched his 3D artist career and came back to writing code
professionally. He is now doing what he really wanted to do since he
was 8 years old—developing games.
These days, Greg lives in a little town called Sandy in the UK with
Kasia and their son, Adam.
I want to thank my loving wife, Kasia, for all her love and
support. Without her, writing this book would be simply
impossible. I also want to thank my loving parents, Ela and
Marek, and brother, Artur, for always believing in me and giving
me exceptional support when I needed it.
https://www2.packtpub.com/books/subscription/packtlib
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Preface
Hello, future game developers! If you are reading this book, you are
probably a curious person trying to learn more about a great game
engine—Unity—and specifically, programming in C#. This book will
take you on a learning journey. We will go through it together,
beginning with the fundamentals of programming and finishing with
a functional 2D platform game.
What this book covers
Chapter 1, Discovering Your Hidden Scripting Skills and Getting Your
Environment Ready, puts you at ease with writing scripts for Unity.
Chapter 4, Getting into the Details of Methods, helps you learn more
in detail about methods and how to use them to understand the
importance of code blocks and the variables used in them.
Chapter 11, The Game Level, helps you learn how to create reusable
pieces of a level and also how to populate them to create the illusion
of an endlessly running game.
https://unity3d.com/unity/system-requirements
Who this book is for
The book is targeted at beginner-level Unity developers with no prior
programming experience. If you are a Unity developer and wish to
create games by learning how to write C# scripts or code, then this
book is for you.
Conventions
In this book, you will find a number of text styles that distinguish
between different kinds of information. Here are some examples of
these styles and an explanation of their meaning.
using UnityEngine;
using System.Collections;
LevelGenerator.instance.AddPiece();
LevelGenerator.instance.RemoveOldestPiece();
}
New terms and important words are shown in bold. Words that
you see on the screen, for example, in menus or dialog boxes,
appear in the text like this: "When you are ready, click on Play in
Unity."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what
you think about this book—what you liked or disliked. Reader
feedback is important for us as it helps us develop titles that you will
really get the most out of.
If there is a topic that you have expertise in and you are interested
in either writing or contributing to a book, see our author guide at
www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a
number of things to help you to get the most from your purchase.
Once the file is downloaded, please make sure that you unzip or
extract the folder using the latest version of:
Errata
Although we have taken every care to ensure the accuracy of our
content, mistakes do happen. If you find a mistake in one of our
books—maybe a mistake in the text or the code—we would be
grateful if you could report this to us. By doing so, you can save
other readers from frustration and help us improve subsequent
versions of this book. If you find any errata, please report them by
visiting http://www.packtpub.com/submit-errata, selecting your
book, clicking on the Errata Submission Form link, and entering
the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our
website or added to any list of existing errata under the Errata
section of that title.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem
across all media. At Packt, we take the protection of our copyright
and licenses very seriously. If you come across any illegal copies of
our works in any form on the Internet, please provide us with the
location address or website name immediately so that we can
pursue a remedy.
-aa
286 LES NOYADES DE NANTES entre les gendarmes,
Goullin, Chaux, Grandmaison, Bachelier, Perrochaud, Mainguet,
Lévêque, Louis Naux, Bollogniel, Gallon, Durassier, Jolly, tous
membres ou commissaires du ci-devant Comité révolutionnaire de
Nantes et dont les noms ont fréquemment figuré dans notre récit.
En même temps qu'eux comparaissait Pinart, un bandit féroce, tueur
de femmes et d'enfants, commissaire, lui aussi, du Comité, et qui,
travaillant ordinairement pour son compte, n'avait point pris aux
Noyades une part active. Dobsent présidait encore les débats; le
substitut Petit occupait le siège de l'accusateur public. La lecture de
l'acte d'accusation fut, pour les Nantais présents, si longtemps
molestés, une première revanche : leurs insolents persécuteurs
étaient prévenus de concussions, d'actes arbitraires, de
dilapidations, de vols, de brigandages et d'assassinats. L'éloquence
du magistrat se donna libre cours : — « Ces êtres immoraux, plus
sanguinaires que Néron, plus barbares que Phalaris, ont commis
tous les crimes sous le masque du patriotisme. Ils ont foulé aux
pieds leur devoir, étouffé le cri de l'innocence, offensé la vertu,
outragé la nature. Jamais la lime du temps n'effacera l'empreinte des
forfaits commis par ces hommes féroces. » Après cet exorde à grand
orchestre, le substitut esquissa un rapide tableau des Noyades. Le
nom de Carrier ne fut pas prononcé, au grand étonnement du
public, tassé dans le prétoire et qui, dans sa candeur, ne comprenait
pas comment on jugeait les subalternes en l'absence du maître
responsable.
I. ECHEANCE 287 Les débats s'ouvrent par les dépositions
des témoins, et Ton voit se succéder à la barre tous ceux que leur
situation a mis en rapports avec le Comité '. Ce qu'on ne sait encore
que confusément, par le procès des quatre-vingt-quatorze, est mis
brutalement en lumière : les vingt-trois noyades, indiquées par
Phélippes, les exécutions d'enfants, les sabrades dans les rues et sur
les places de Nantes, les Marats épui>le fatigue à force de frapper
les victimes, l'enfer de l'Entrepôt, le cynisme grivois des bourreaux...
C'est à cette avalancbe d'atrocités jusqu'alors inouïe que le
bonhomme Mercier fait allusion quand, s'adressant au Tacite ou au
Shakespeare futurs qui devront les raconter, il écrit : — « Fais ton
idiome, car tu auras à peindre ce qui ne s'est jamais vu. »2 A chacun
des témoignages le drame se renouvelle : on croit avoir touché le
fond de l'épouvante : mais la déposition qui suit renchérit sur la
précédente et des cris d'épouvante accueillent ce perpétuel
grandissement d'horreur. Quand paraît le cocassier Leroy, qui, seul, a
échappé à la noyade du 24 frimaire ; quand, simplement, il raconte
son prodigieux sauvetage, une grande angoisse étreint l'auditoire :
dès qu'il a terminé sa déclaration, les cris éclatent : il est acclamé,
embrassé ; quelques citoyens font une quête dans l'assistance et
remettent au pauvre garçon. ' Afin d'éviter les redites on se contente
d'esquisser ici, à grands traits, ce procès fameux, ensuivant le
résumé qu'en a écrit, d'après le dossier des Archives nationales, M.
Campardon, Le Tribunal révolutionnaire de Paris, II, p. 42 et suiv. *
Le Xouveau Paris, par le citoyen Mercier. Avant-propos.
288 LES NOYADES DE NANTES tout ébaubi de son succès,
un gros paquet d'assignats. Voici une poissonnière, la femme Laillet,
qui, détenue et servante à la prison du Bouffay, a vu, dans la geôle,
Mme de la Métaierie et ses quatre filles, qu'on disait cousines de
Charette. L'ordre vient de les livrer sans jugement à l'exécuteur et le
concierge charge sa domestique de les prévenir. La femme Laillet
entraîne les malheureuses dans une chambre et leur dit : — « Mes
amies, votre dernière heure approche, préparez-vous; Carrier
l'ordonne ; à neuf heures vous ne serez plus. » Toutes se jettent la
face contre terre et prient ; la plus jeune, — elle a dix-sept ans, —
remet à la citoyenne Laillet une petite bague ; puis, sanglotant,
serrées contre leur maman, elles vont à la mort. Le bourreau,
quelques jours plus tard, en trépassait d'effroi et de remords1. A
l'audience, la femme Laillet tire de sa poche l'étroit anneau, legs de
la petite mourante, le montre aux juges tandis que la salle s'emplit
du bruit des sanglots et des rumeurs de pitié. Pendant que parle
l'officier de santé Thomas, évoquant la pestilence des prisons, l'émoi
devient tumultueux : il a vu les baquets d'ordures de l'Entrepôt où
flottaient des corps d'enfants agonisants ou morts ; il a constaté la
noyade de trente femmes sur le point d'être mères ; il a visité à
FEperonnière et à 1 L'exécution des dames de la Métaierie eut lieu le
19 décembre 1793 et l'exécuteur mourut au début de janvier. On ne
sait, à la vérité, si, comme le dit la femme Laillet, cet homme
succomba aux remords. Voir La guillotine et le bourreau à Nantes,
par A. Lallié.
L ÉCHÉANCE 289 la Masilière huit cents femmes et enfants,
entassés sans lits, sans paille, sans pain, sans feu, sans eau et dans
un tel état de misère que cinq enfants sont morts sous ses yeux, en
moins de quatre minutes. 11 accuse le Comité d'avoir jeté dans la
Loire quatre ou cinq cents enfants : c'est Jolly qui paraît avoir
présidé à cette affreuse expédition. Des clameurs interrompent la
déposition : le public proteste : — « Carrier ! Carrier ! » et menace
de ses huées les accusés qu'on aperçoit, dominant la cohue, tantôt
effondrés et tantôt insolents : Goullin, encore fanfaron, Chaux,
emporté et discutant, Bachelier, très calme, écrivant sans lever la
tète ; les autres, anxieux, rageurs, sournois, ergotant; à la précision,
à la concordance des dépositions, ils opposent des explications
diffuses ou pénibles. Perrochaud déclare que « ces propos ne sont
imaginés que pour jeter de la défaveur sur les travaux du Comité ' »
; Jolly avoue avoir lié des détenus destinés à la noyade : — « Mais,
dit-il, à mon tour, d'autres m'ont garrotté pour me traduire au
tribunal... » Et il se juge quitte envers ses victimes2. D'ailleurs, il n'a
fait qu'obéir : — « J'ai toujours été persuadé que je n'étais qu'un
domestique que l'on employait au besoin, que l'on payait et qu'on
renvoyait de même3 ». Grandmaison assure n'avoir jamais participé
à aucune noyade ; mais « il a entendu la hache qui précipitait les
prêtres dans les flots ». Comme le président lui observe qu'il devait
être à ' Bulletin, VI, n° 84, p. 335. 1 Bulletin, VI, n» 70, p. 279. 3
Bulletin, VI, n« 81, p. 322 19
290 LES NOYADES DE NANTES une bien faible distance du
navire pour entendre les coups qui l'ont coulé à fond, il répond : — «
Il y avait de petits bateaux à la faveur desquels, nous, membres du
Comité préposés à la surveillance de cette expédition, nous nous
sommes éloignés; mais je n'ai pas vu la hache qui a porté le coup
fatal. » Pourtant, accablé sous les déclarations de ceux qui l'ont
aperçu, sabrant les bras et les têtes au moment de l'enfoncement
des gabares, il finit par arguer du cas de légitime défense : — « Si je
m'étais rendu coupable de pareils excès, je serais en quelque sorte
excusable, parce que j'étais dans une espèce d'ivresse et que je me
battais à mon corps défendant contre des gens qui voulaient me
couler à fond avec eux. » — Quel danger pouviez-vous courir avec
des individus enfermés dans une loge de bois?... — Il n'en est pas
moins vrai, bougonne le noyeur, que les détenus faisaient des
mouvements inquiétants, et qu'il nous était bien difficile de les
contenir \ Goullin a des euphémismes sublimes : — « Naturellement
bouillant et brûlant d'un zèle peut-être trop ardent et mal entendu
pour la chose publique », je n'ai pu « me défendre d'une certaine
animadversion pour les aristocrates »... Voilà son défaut. Aristocrate,
il l'est lui-même, d'ailleurs, et professe le plus profond dédain pour
ces paysans dont on lui reproche la mort. — « Les prévenus noyés
ou fusillés, dit-il, étaient tous des gens sans aveu, n- Du reste ces 4
Bulletin, VI, n° 90, p. 358. '- Bulletin, VI, n°6l, p. 242.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com