Learning C# by Developing Games with Unity
C# Programming for Unity Game Development
by
Emma William
For information contact :
(alabamamond@gmail.com, memlnc)
http://www.memlnc.com
nd Edition: 2020
Learning C# by Developing Games with Unity
Copyright 2020 by Emma William
The joy of discovery is one of the fundamental joys of play itself. Not just the joy of discovering secrets within the game, but also the joy of uncovering the creators vision. Its that Aha! moment where it all makes sense, and behind the world the player can feel the touch of another creative mind. In order for it to be truly joyful, however, it must remain hidden from plain viewnot carved as commandments into stone tablets but revealed, piece by piece, through the players exploration of the games rules.
Derek Yu, Spelunky
.
Who this book is for?
If you don't know anything about programming in general, writing code, writing scripts, or have no idea where to even begin, then this book is perfect for you. If you want to make games and need to learn how to write C# scripts or code, then this book is ideal for you.
memlnc
Who this book is for?..............................................................................................3
INTRODUCTION___________________________________________________13
2D OR 3D PROJECTS..14
Full 3D.15
Orthographic 3D..16
Full 2D.16
2D gameplay with 3D graphics..17
Why do we use game engines? 19
Quick steps to get started with Unity Engine.20
CHAPTER 1_______________________________________________________25
The language C #26
syntax.28
Comments28
variables29
Naming conventions29
Data types..30
Variable declaration with initialization.32
Boolean variable33
Keyword var.33
Data fields / array.33
Create arrays34
Access to an array element35
Determine the number of all array items35
Multidimensional arrays..36
Constants37
Enumeration38
Type conversion38
Ramifications..40
if statements40
switch statement41
grind43
for loop43
Negative step size44
Break.45
Foreach loop46
while loop..47
do loop48
Classes.49
Assign components by code50
Instantiation of non-components.51
Methods / functions.52
Don't repeat yourself54
Value types and reference types.54
Overloaded methods..56
Local and global variables56
Prevent confusion with this57
Access and visibility .57
Static classes and class members..59
Parameter modifier out / ref61
Array passing with params63
Properties and property methods65
Inheritance68
Base class and derived classes69
Inheritance and visibility.70
Override inherited method72
Access to the base class73
Seal classes74
Polymorphism.75
Interfaces76
Define interface.77
Implement interfaces78
Support from MonoDevelop.80
Access via an interface.80
Namespaces.81
Generic classes and methods.83
Cunning..84
Sort list objects.86
Dictionary.87
CHAPTER 2________________________________________________________90
Script programming..90
Script programming..90
MonoDevelop91
Help in MonoDevelop..92
Syntax error92
Forwarding of error messages.93
Usable programming languages.93
Why C #?.94
Unity's inheritance structure94
Object.95
GameObject..96
ScriptableObject.96
Component.97
Transform97
Behavior97
MonoBehaviour..98
Create scripts98
Rename scripts100
Rename scripts100
The script framework.101
Unity's event methods.102
Update103
FixedUpdate104
Change time interval.104
Awake.105
begin105
OnGUI.106
LateUpdate.107
Component programming108
Access GameObjects109
FindWithTag..110
FindGameObjectsWithTag..111
Find.112
Activate and deactivate GameObjects..113
Destroy GameObjects113
Create GameObjects.114
Access components..115
GetComponent.116
Reduce traffic117
SendMessage117
Variable access119
Add components120
Remove components.120
Activate and deactivate components.121
Random values121
Execute code in parallel124
WaitForSeconds.126
Delayed and repeating function calls with Invoke.127
Invoke127
InvokeRepeating, IsInvoking and CancelInvoke..128
Save and load data..130
PlayerPrefs preferences..131
save data131
Check the key.133
Clear..133
Save134
Cross-scene data..134
Passing values with PlayerPrefs.135
Use start menus for initialization.137
Prevent destruction..139
DontDestroyOnLoad as a singleton141
Debug class142
Compilation order.143
Execution order..145
CHAPTER______________________________________________________________147
Create a simple 3d game..147
Level design149
General import settings.150
Create a dungeon..155
Create floor155
Create walls156
Create ceiling157
Add fire and light..158
Create decoration159
Create an inventory system162
Management logic162
Interface of the inventory system171
HoverEffects174
Default cursor.177
key..177
Water tank178
Game controller..182
Create players182
Life management184
MessageText.185
LifePointController..186
HealthController188
PlayerHealth..190
Player controls.198
Develop throwing stone210
Configure bursting stone.215
Create a quest.218
Manage experience points.219
Create quest givers..221
Quest giver configuration222
Create sub-quest..232
Place and configure objects..235
Create opponents.237
Create Animator Controller..241
Create a NavMesh244
Recognize surroundings and enemies..246
Manage health status..251
Develop artificial intelligence.256
Opening scene..264
Create a starting scene..265
Create start menu.266
Start menu with OnGUI266
Web player adjustments..271
Change web player template272
Changeover to uGUI..272
Script adjustments.272
CHAPTER 4_______________________________________________________274
Create a simple 2d game275
Special attacks for projectiles..291
Ejector industry.......299
INTRODUCTION
Unity is a cross-platform development platform initially created for developing games but is now used for a wide range of things such as: architecture, art, children's apps, information management, education, entertainment, marketing, medical, military, physical installations, simulations, training, and many more.Unity takes a lot of the complexities of developing games and similar interactive experiences and looks after them behind the scenes so people can get on with designing and developing their games. These complexities include graphics rendering, world physics and compiling. More advanced users can interact and adapt them as needed but for beginners they need not worry about it.Games in Unity are developed in two halves; the first half -within the Unity editor, and the second half -using code, specifically C#. Unity is bundled with MonoDevelopor Visual Studio 2015 Communityfor writing C#.
2D OR 3D PROJECTS
Unity is equally suited to creating both 2D and 3D games. But whats the difference? When you create a new project in Unity, you have the choice to start in 2D or 3D mode. You may already know what you want to build, but there are a few subtle points that may affect which mode you choose.The choice between starting in 2D or 3D mode determines some settings for the Unity Editor -such as whether images are imported as textures or sprites. Dont worry about making the wrong choice though, you can swap between 2D or 3D mode at any time regardless of the mode you set when you created your project. Here are some guidelines which should help you choose.
Next page