Game Advanced Prototype 1
GCC Academy
Hello
This is Youngho Lee for shooting game production
Creating a game with Unity
includes board games, shooting games
FPS and TPS games
and MMORPG games as well
so variety of 2D or 3D games
Making all these games of various genres
means that there must be a virtual world
simulated
In shooting game production
we will learn about mechanics and vector
to create that virtual world
and will create a shooting game
Starting a project
will be done in a practical way
First, we'll separate the prototype version
into four steps that create the core content of the game
Then on alpha version
to have all production elements included
it will be done in two steps
Lastly in beta version
we will learn about the optimization and management of games
Through this 3 step production process
you'll get familiar with the overall project production process
Let's first learn prototype 1
for shooting game production
In this unit
we'll create a project
and learn how to set that made project
And major game objects
that is, camera, lighting, and player
will be made and we'll learn how to set them
Lastly, in Unity Engine
and main life cycle function
Project Production and Environment Setting
Let's get started with
project production and environment settings
First open up Unity Hub
and let's create a new project here
We're currently
creating a project with the 2022.3.49f1 version
Here, we'll do basic project
3D (Built-In Render Pipeline)
Select this one
and name that project Shooting
Click on create project to create
Once a Unity project is made
it will load the necessary resources
and compile
Once it's made like this
let's set the environment of this project
First of all
my screen looks like this
which is how I organized it
but your screen will have it
like this by default
This, from layout here
click on the button 2 by 3
and then the screen will look like this
The layout has changed
Hierarchy, Project, Inspector
Here I'll drag the
project tab
to put it down here
Put it under hierarchy
Let me push this one a little and put it like this
to make the layout neater
Then on the left, we have the scene window
and under that is the game window
In the middle, hierarchy, and under that, project
And lastly
the inspector window
This is how I'll have the layout be
Then now we'll do a shooting project
let's start with a 2D mode
We're not actually making a 2D project
but we'll expand from this
like making a 3D project from a 2D project
so let's start from here
First, on the scene window
switch that to 2D mode
you can click on the 2D button
but this way
it might bother us during other parts of the production
So don't click on the 2D button
and instead on the top right
there is Gizmos
With that Gizmos
Here it says persp
which is short for perspective
Click on this and change it to Iso mode
Here there are X, Y, Z
X, Y, Z
There are these three axes
Click on this and the Iso part
will change
Let's try
Click on x and it changes to right
Click on y and it changes to top
and click on z and it will change to front
2D mode is looking from the back
so we'll have back mode
I'll click the part
opposite from z
This is front so the back
will obviously be here that you need to click
Then it changes to back
and there are Iso mode lines, three of them
Then the perspective mode
shows depth perception
So when an object is in front it looks big
and when it's far then it looks small
When the object is behind there
it will look small like this
But these three Iso
are Isometric view
This is used in 2D mode production
Usually 2D mode
is expressed using only two axes
We call this two axes ones
orthopraphic
and there is no depth
Since there's no depth there is obviously no perspective
So in 2D mode, we have it like this
and work on it
The 2D button here
If you click on that, it only gets rid of the Gizmos
the screen actually looks the same
Let's me close the 2D mode again
and work on it like this
Camera and Lighting Placement & Player Object and Script Production
Next we'll see camera and lighting placement
On the screen, on hierarchy
there are main camera and directional light
We're in 2D mode so here, camera
and directional light, these two are here
The light part
might not be needed for 2D
The recently added Unity feature
provides a function where light is applied in 2D mode
but this is only when advanced features are used
and in basic 2D, we do not need lighting that much
First let's set the main camera
The camera has perspective now
I'll change it back to perspective mode
Click here
And when you select
camera
you can see
I'll move a little faster
Like this, a trapezoid
shows up, right?
It has this trapezoid shape
From the side
it has this shape
Right? Like this
Let's go back to 2D mode
It'll look like this in 2D mode
We call this part
View Flow Stem
and when we're expressing perspective
it has this trapezoid shape
Right? A trapezoid
But we're going to work on it on 2D mode
so this must change
Once you've selected main camera
on the right's inspector window
we will be able to edit the detailed properties of the main camera
Among the components, there is camera component
Here, projection
is what let's us change the camera property
Projection is there too
3D is basically
expressed on a 2D screen
There is a flow that it follows
which is the 3D rendering pipeline
Here, this projection
the 3d rendering pipeline
goes through the process of projection
and here we choose if the object
will have perspective
or not, so if it'll be 2D
You can think of it as the camera having
a 3D lens or a 2D lens
You can see perspective here
this is what expresses the perspective
And on the bottom
open this by clicking on the dropdown button
and it says orthopraphic
This is what changes it to orthogonal coordinate system
Then on the screen
with main camera
it shows a rectangular shape, unlike before
Change this to Iso
to Isometric view
it shows this rectangular shape
Then this has a orthogonal coordinate system
which is perspectiveless and 2D
On the 2D scene, not only this
but when we're making a 2D project
the camera also has this content applied
Get it?
Let's work on it like this
Next is directional light
In 2D mode, we don't need lighting
So let's deactivate
the light component and turn it off for a second
You can also erase this
or just turn it off like I did
then there will be no light
Then it will show dark images
So now let's work on
how it could show the original object image colors
by working on the settings
When you go to the very bottom in window
it says rendering here
Window menu, rendering
and there's also lighting
Let's open that
Then a lighting window appears
First, we'll check if the auto generate
is deactivated
If this is checked
every time we move an object
There's this thing called lightmapping
It's putting light on objects
giving an effect of a screenshot
but that takes a long time
and in 2D, we don't need that
so let's have that deactivated
Next, here on environment
click on the second tab
Here, in the world we're working on
there are three lights
The basic light
is directional light
Directional Light
This is like sun rays
Only one direction
Can that happen?
Sun shines light to everywhere
360 degrees, no?
But from the Earth's perspective
if the sun is here
we view it as there being just one direction that's coming to Earth
So it's one direction for afar
This directional light
when there is a person on Earth here
how close we get to the sun
might not matter much
Us getting 100m closer to the sun
doesn't make the light or energy from the sun different
Getting 1,000km closer
doesn't make that big of a difference
Since we are millions of kilometers apart from it
it really does not matter much
But what angle the sun is shining on Earth
does influence us
So this directional light
is not related to location
but is with direction
It is related with direction
It influences us
Next, apart from this directional light
there is also point light
This point light
literally puts this point as the center
and the light spreads in 360 degrees
An example of this
is a torch
When we light a torch
the light spreads in 360 degrees with this as the origin
Right? Normal lights that we have at home
Those are all like this
So this point light
means light that spreads 360 degrees
from the center object
the light as the origin
Next is spot light
and this is light car's headlights
If a car is like this
it'll also have wheels
and with the car like this
there will be light spreading from this car
These lights, strangely
spread in a circular sector shape
like this
We call lights like the car headlights
a spot light
So there are three main types of lights
and each of them have their own directions
Direction light goes in one direction
and for point light, location matters
Location matters to it
and the direction is 360
Right?
And spot light
is like headlights
Depending on how close this is
it can shine brighter or less
So location matters
and will have only certain direction
only certain angles
Right?
Anyways these three lights
have the common property that they have directions
Understand?
They all have directions
So then if there is light
These lights with directions
When affecting our objects
Shining light like this
As it hits a surface
it will be reflected
Depending on the type of reflection
Depending on how it's reflected
it can again divided into three types
Of course, apart from directional light
spot light, and point light
there might be other lightings according to different engines
But those are not existent in real life
but just made in the engine
But basically in real life
there are these three types of light
Then what I'm going to tell you now
is when this light hits a surface
depending on how it's reflected
it can again be divided into three
First, the surface looks smooth
but it might actually
be bumpy if you look closer
Then when light hits it
like this
what would happen?
When the light came in like this
it will hit the surface head to head
and here
the light will be reflected like this
Right? Since lights reflect on surfaces
Got it?
So when light comes in
the surface looks smooth
but if there's actually
tiny bumps on it
the light isn't just reflected simply like this
but how does it go?
Diffuse reflection happens
Right? We call this diffuse reflection
or diffuse light
Diffuse light or diffuse reflection
Diffuse in English
Diffuse light
So when light comes in
these have this property
so this part diffuses
and the part behind becomes dark
This part is dark
Why? Light doesn't reach here
Right? Let me move this a little bit
What other light is there
This is called diffuse light
Light comes in and gets reflected
Let's say we're actually looking at this
Like this, right here
and light comes in
then gets reflected and reaches our eyes
It bounces off and reaches our eyes
Then what happens?
We say 'oh it's so shiny!'
Glaring
In that case, the surface looks
like this
Something like this
You've seen something like this right?
These are what?
Lights that directly reach our eyes after being reflected
We call them specular
In English, specular
Specular
Next is a basic reflective property of light
It has the property of infinite reflection
Let's say that the light didn't hit the object
but the cloud up here
There are clouds, then the light will bounce off of it
then it will bounce off the ozone layer and come back down
reflect again on the ground, then on a desk
infinitely on this object and that
It will keep bouncing off of objects
When infinite reflection happens
Then at some point, when there is an object here
Right? Light comes this way
and will reflect this part again
Then at this moment
if you look at the bottom of your desk
even the parts that aren't lit by light will not be completely dark
Right? It has light in darker colors
We call this ambient
When you're studying
or trying to get good sleep
you listen to ASMR
A from that means ambient
and A of ambient is the short for ambient
Ambient
It's an m here
Ambient
So with these three types of reflections
three lights are combined
and it shows the
object like this
Good?
When we look at our screen
if you go to lighting setting and to environment
Here, ambient
From there, source to skybox
so the sky color reflected in the sky
will be applied as the ambient light
Hitting the object surface, the ground
the part that affects the object
We choose which one? Skybox
Skybox, it says box here
These days, there's also spheres
instead of a box
but here, you can just think of it as a cube since it's a box
Then how is it?
Since it's a cube, there are 6 sides
We have combined the images here
Then where do we put the user?
In the middle of the object
Inside this box, then it can make it looks like
we're in this world
This is the process
of making these environment in 3D
The effects you see in the sky here
This is what it means
The part shown in the sky
We're taking that as the ambient color
So if an object is here like this
the ambient bounced off
We're going to use that color
That's how it is
But in 2D, we don't use that ambient as is
but just the color we designate
Here, on source
choose color instead of skybox
and the ambient color was
dark grey, a dark color?
Blue and dark color, right?
Let's put white here
white is 1 in numbers
1, so in RGB
we can express each colors from 0 to 1
RGB, every color
can be expressed in the range from 0 to 1
So if the color is red
we can have 1, 0, 0
Then if I multiply this
to the ambient color I made
For a color to show it's color itself
just multiply the number 1
Then it shows its color as is, right?
If it's 0.2, it will be darker right?
So if you put white which corresponds to the number 1
it shows the original color as is
Great
Let's put this as that
We have now done camera, directional light
and light setting
Now let's move onto resolution settings
On 2D as well, we're going to make
a vertical scroll instead of horizontal
So we'll put it here
and put the plane here
and we'll make it look like the enemies coming from
top to bottom
So let's set the resolution
Here, free aspect
Free aspect on the game window
You'll see that
Open this dropdown
Right? Then click on the add button
I, here
then on the label
let's say shooting
Then for type, fixed resolution
640 for width
and Y, Y is height
We'll put 960
Ok
Done? Now on the very bottom
it says shooting, right?
So it was free aspect on the game window
Now we can see the screen
set as shooting
Now let's make the player object
and script
and move onto the next project
First, we'll make a player object
Click on the plus button on hierarchy
and create a cube on 3D object
We're working on the prototype now
Prototyping basically verifies the logic
and see if
our project is fine
So we make a cube
and when we move onto the alpha version
we'll add all
the planned content
so we'll update them all to practically used data
Create a cube on 3D object
and there's a cube
This game object's name
will be player
Let's put player
Then for location, from transform
right click and reset
Then you can see that all values for
position, rotation, and scale are set back to default
They're all 0, 0, 0
In the game world
Where is the player in this world?
The very center of the virtual space
0, 0, 0
But below there
on the game window, where is the player?
It's here
Isn't it a little more to the bottom?
Right? The reason is
This is in fact 0, 0, 0
but the screen coming down like this
The game object that shows the screen
is the main camera
This camera is currently at
If you look at this scene window
it's a little above here
And on the right, the inspector window
what's the y for position?
It's 1 right?
We'll set that lower to 0
and z at -10
Great
Then the camera is, compared to the player
Let me see form the side
like this
z means front or back
Then the object is here
and the main camera is behind there
You can actually go there to see
Main camera is here
filming like this
So the scene the main camera is seeing
is the back of the player
like this
These objects will show up
like this
Then the screen captured by the camera
shows up on the game window
Good?
So the position of the main camera will be 0, 0
and -10 for z
Then we now have done the basic resolution settings
and also the camera and player
We set the camera's location values as well
and same for
the player's location
Then to control the player
let's make a script
First, on the project window
Click on plus from asset folder to create a folder
and name it script
Go in to the script folder
and let's make a script
to control the player
First, we're going to make the player write movement codes
So on script, click on plus and then C# script
and name it PlayerMove
Good?
What you should remember here is
Look at this name in PlayerMove
You have to keep the capital letters exactly like this
P in capital
and M as well
plus no spaces
Do not put spaces
PlayerMove
When you select this
on the inspector window on the right
it says public class PlayerMove right?
This part that says PlayerMove
and here where it says PlayerMove
These two must be identical
Only when the file name and class name are the same
there will be no errors
'But I wrote it wrong'
then we'll fix it later on
Go to edit
and this part on the edit window
change it back to PlayerMove
If that worked properly
Drag and drop PlayerMove
to this player
Drag and drop
and then the PlayerMove is in here
You can put it in with drag and drop
Another thing, if you did it wrong
right click
and click on remove component
Get it? We just put the player part here
but now select the player and on the right
We'll put it on the right side
Drag and drop like this
then the PlayerMove is added again
There are two ways, the other one is
You can add with component here
but we usually don't do that
Usually
we use drag and drop
or you can use add component
by clicking here
Great, now we put PlayerMove
in our player game object
Understanding Unity C#'s basic structure
Now we'll really get into
writing the script that controls the player
To do that, it would be nice to see
how Unity C# works
So in this unit, we'll learn
the basic structure of Unity C#
Although you already learned C#
the basic grammar used in C3
can also be used the same in Unity C#
But in Unity C#
there is using UnityEngine
This is called a name space
We need to add the name space we're going to use here
You need to say that you'll use UnityEngine
to use other classes or API functions
provided by Unity
And if you see here
on public class, the class name is
PlayerMove
If this part is wrong
then you can just fix that
And then after that
there's a super class, MonoBehaviour
If you follow this
in API
above this is
Behaviour
There's Behaviour
and above that is
Component
So what's the most super of MonoBehaviour? Component
and PlayerMove which inherits MonoBehaviour
is also a component
So what are we writing?
Component
So to game object
There is the game object that we're using, Player
We could drag and drop
PlayerMove
Why is that? Because this is a component
Everything that consists the game object Player
are components
The reason why it can stick
is because PlayerMove is a component
Get it? Next
Under here we have a function called void start
and void update
These two functions
are what we call life cycle
Life cycle function
Life cycle is
from birth
then do you die right away?
You can't go straight to the tomb
That's a little dangerous
It's cruel, we must let them live a little
So they live, and then what do they do?
They die
I said birth but
these are all verbs, to be birthed
To live, right?
Functions do the job of verbs
They act as verbs
Here
Let me just move this away
Let's talk about life cycle
briefly
Being born
Can you know when you are being born?
Could you?
Can we know when a baby is being born?
We can, why?
When you visit an ob-gyn they tell you
when the baby will be born, the date and time
So we can know when they are born
It is influenced by our wills
In fact they do give births on their wish day by surgery
If we say that we'll do this at this time
we can designate when this action will
be done
And what about living?
You live, but then dying?
Do you know when you die?
This is tricky
And let's say we're meeting in real life
and we're giving each other high fives
Does the hand look AI?
I don't think I'm much different from an AI
Let's say we do high fives
We clap them
Two hands will clap
Clap it now? Or not now?
Can you tell when?
You can't
These things, dying, clapping
these are hard to know when they'll happen
So we say that these exist as events
So in Unity, the birth is called start
and life cycle isn't just about being birthed
but there will be a point in time when the baby is made
Then when their limbs develop
Life cycle is cut into very tiny pieces
But overall, we can just say that
it's birth, life and death
Being born is start
and this start here is what this is
Living is update
which is here
and did we say we know when we die?
We can't
So in Unity, it shows the events
that we cannot predict when
So those have On in front of them
They have the prefix On
So dying is OnDestroy
The function name is designated
These life cycle functions
are what Unity provides
It makes start and update
once a class is made
How many times is something born?
Not like Samsara
It's just once right?
Living will just be lived
until just before death
And how many times do you die? Once
So we can know how many times these functions are called
Being born is matched with start
so called how many times? Once
Update will be called all the time while living
and OnDestroy, just once
when it dies
You could remember the timing
and number of calls of the functions
And then with this, the core of programming
let's put Hello World at first
Let's try
The player already
has the PlayerMove component
Let's open this one
When PlayerMove script is opened on Visual Studio
we can put codes here
print, Hello World
Let's type that in
Save it
and come back to Unity
Then Unity immediately reads the saved part
and shows us
and automatically it recognizes
the changed parts and memorizes it
Let's click the play button
Then it says hello world
Where is it?
Can you see?
Look at my mouse cursor
Down here, can you see?
It says hello world, tiny
If it's hard to see
try clicking on hello world
then it shows a console window
Here it says hello world
and also has collapse
If this is pressed
it shows how many times this was called at the end
It means that we called it once
Why? Because there is only one start
Where should we put this console window
Let's put it next to
the project window, dock it
Then I'll turn it off
When you run it again
From now on, on the console window
you can see this part being marked over and over again
So that was hello world
But as I told you, life cycle function
is called once in start
continuously updated
and death also called once
Let's see if this
actually does happen
If there is start, for this part
I'll put it in update
Then it was called once
Now let's see how this part is called
Press play
As you can see, at the end of hello world
the number is increasing
Right? This part is consistently increasing
It means that this is being called constantly
Why? Because update is called continuously during life
Then let's see how
OnDestroy is called
OnDestroy
If you put void OnDestroy
Not on update but on OnDestroy
and let's test that
Save it, you must save it
Play it again
It doesn't show hello world now
Let me turn it off
Then only then hello world appears
You can see it being called once
So start, update, OnDestroy functions
so the life cycle function
is called like this
and on start, when we're doing some sort of setting
or such works
When setting the initial values, put it in start
because it's called just once when being born
and update is after it starts living
Here, animations
like characters moving or receiving user input
These are all done where? Update
because it must perform it continuously while living
While the game is running, it's all update
And when we end it, returning resources
or other such works are required sometimes
Then we can do that on OnDestroy
Then what structure does unity have
making it possible for Unity editor
to acknowledge and run it
right away?
C# files' extensions are .cs
What makes C# files aren't just Visual Studio
but other IDE tools as well
There is also Visual Studio code now
We are using Visual Studio
community
We can make C# flils with just a memo pad
So C# file is made
and once we do that
How does Unity Engine recognize this?
The C# file was edited on Unity
then the editor is monitoring it
Oh, C# file was edited
Then it loads C# file
and it's not just using the C# file
Between here, the C# file we made
is human language
How is it?
It's programming language
It's a human language just to communicate with computers
Then C# file made with human language
must be performed where?
On a machine, a computer
So the language humans made
the language we made in Korea
must be translated to communicate
with an American person
Just like that, C# file's language
must be translated into machine code
What we call this translation is
compiling
Compile
So when we bring a C# to Unity
Unity loads that file
and compiles it
But uniquely, C
or C++ is translated into machine code right away
But it doesn't for C#
and this is to secure the flexibility
for many platforms
We don't have just one OS
When we put an app on OS
then it changes into Window OS, Mac OS
or iOS
So according to the OS
the app can only be very dependent
Processing certain data
is also different for these languages and C#
So if an app becomes dependent on the OS
when it's trying to correspond to other OS
the application we made
for iOS, iPhone, android phones
Window, or steam
it might be hard to correspond it to them
Why? because each OS are different
Then to correspond multi platform
to one source code
what should we do?
If we translate it right away to machine code
it becomes difficult
so C# puts something in between here
like this
This is .NET
.NET
It's often called runtime
So this part
.NET
the role of .NET is
when we make an app, instead of going straight to the OS
it goes through .NET first
and then when running on the OS
it determines for the OS
and compile then
Then does it not compile before that?
It does, in what way?
Here, you can see Make DLL
These C# files
are called Intermediate Language
It makes this an interlanguage
That is DLL
In C#, we say assembly
Make all these
and the extension comes out as a DLL file
C# is turned into a DLL file
Then these are Intermediate Language
Instead of going straight to the OS
it goes through something in the middle
making it an Intermediate Language beforehand
After that, for Window OS or iOS
Only then it compiles to machine codes
suitable for the OS
So compile at that moment
when? That moment
So it's called just in time
and in short, JIT compile
This leads to the final
machine codes
So C and C++
are compiled directly to OS
into what fits the OS
so it can be quicker
But what about JAVA or C#?
It goes through something
So compared to C and C++
it might be a little slower
These days though, thanks to hardware and compiler capacity
this is also getting shorter
Unity has this
It's using C#, so this part is also included
which is why what we're working on on Unity
can be used in android, iOS, Console
and even in web browsers
We're making use of the pros of this part
Then you'll be able to understand
the basic structure of Unity C#
Let's see what we've learned in this topic
First, we created a project and set the environment
Then we placed camera and lighting
After that, we created player object
and added script
Lastly on Unity Engine
we saw how C# works and it's components
Good job
Project production and environment setting Setting shooting game project
Run Unity Hub and create ShootingGame project When ShootingGame project is made, Unity is ran
Setting up production environment Change the Scene view to Iso mode and click Gizmos to set the screen to be a back view
Camera and lighting placement, player object and script creation Camera Settings Camera components are attached to the camera to act as a camera
Set main camera's projetion as orthographics Lighting setting Select direction light from hierarchy window and deactivate light component
Open [winow-rendering-lighting settings] window and deactivate auto generate option at the very bottom of lighting window's scene tab
Change Environment lighting source to color and designate ambient color to white on environemnt
On game window, open resolution dropdown menu and blick + button and set resolution x, y value to 640x960
Player object and script setting Click on + button from hierarchy window to create [3D Object - Cube] and name it Player
Click on + buton from project window to select folder and name it Scripts
Click on + button from script folder to make C# script and name it PlayerMove
Drag PlayerMovve script and drop on hierarchy's player object
Understanding basic structure of Unity C# Double click on PlayerMove.cs from Project window to open editor
Input print("HeloWorld") to PlayerMove.cs' start function and run on Unity
Life cycle function Unity object's life cycle is Start as birth, Spdate and life, and Ondestory as death
C# script's run structure Change in CS file let's Unity Engine compile the file Usually compiled to Assembly-CSharp.dll