Learn Unity and C# Programming (2024) | 5h Unity 2D Course | FREE Unity Tutorial
FULL TRANSCRIPT
hi there my name is michael moore
founder of wm development and my goal is
to make you the best game developer and
the most fun way possible the course
you're about to watch right now is a
course that i have on udemy and
skillshare that has hundreds of super
positive reviews and today i'm going to
give it to you for free well not all of
it because i still have to pay my rent
somehow give me rent you'll get your
rent when you fix this anyway you can
support me by leaving a comment and
hitting the like button somewhere down
here and if you got to the end of the
course or you are somewhere in the
middle and you want to get the full 10
hour version
just scroll down to the description and
i've left their links with that you can
use to get either to get it either on
udemy or skillshare whichever you prefer
of course with a special coupon to save
you a bit of money i'll also leave a
link to the discord server that you can
use to join
our great and growing community where
you can share your game if you have any
questions you can ask them and you can
help out by answering some questions
there also finally if for some reason
the links in the descriptions don't work
you can contact me either on discord or
on instagram or on linkedin and i'll
help you out now let me give you a quick
guide on how to watch the course and how
to navigate through the long video so if
you're a total beginner i recommend that
you start off at the very beginning from
the first course where we start with the
very basic introduction and downloading
unity and all of that good stuff and if
you want to refresh your memory a bit
you already know your way around a bit i
recommend that you start at this time it
will be somewhere around me and you can
start from that video or that time stamp
it will immediately take you
you will not have to go through the
downloading and all the small processes
you will just start up where the course
begins and if you are already a seasoned
unity user and you just want to see how
this course is made and what you can do
then i'll also leave a timestamp
somewhere around here that you can use
and just get into the neck of it the
video will be timestamp so in here down
below on the bar red bar everything
should be timestamped if not i will
leave the timestamp in the description
so you can go to any video that you like
i also use sourcetree which is a very
powerful tool
so i recommend that you watch the video
or the little section which should be
around here on on the source tree it's
like maybe a 16 minute video it's not
necessary to complete the course but
it's a very powerful tool and i do
recommend that you check it also i
recommend that you watch the how to use
this course which will give you the
basic ideas because i have challenges
and stuff anyways good luck and remember
to have
fun
[Music]
welcome back everyone so in this video
we are simply going to be downloading
unity hub
installing our
version of unity and setting up
everything in order to start creating
games
so
let's get started first thing you need
to do is you need to go into whatever
browser you're using i'm currently using
google chrome it doesn't matter
simply go ahead to google and type in
download unity hub and you should get
this search result so simply go and
click on the download unity hub it
should be the first link which should be
on the unity3d.com
website and it will take you to this
page right here and it will ask you to
download unity hub now what is unity hub
well unity hub is a place
where we can add different versions of
unity
and we can also
have all of our of all all of our
project represented very neatly and very
carefully which is very helpful and much
better than as the way we used unity
before that
so simply click on download unity hub
and you should get the installation
which is right here which is unity hub
setup so double click on that and it
will start an installation it's fairly
easy you simply click on agree and
install it in whatever destination
folder that you have i already have
unity hub so i won't bore you with the
download process it will ask you to
agree to something which is fairly easy
so go ahead and install unity hub
okay so now that you have unity hub
installed you should you should
get this window right here and first
thing you'll need to do because i'm
already signed in so you need to create
an account i'm currently using my
google email which is very helpful and
much easier
and here you can see that we have all of
our projects now currently we don't have
any projects yet but we will very soon
here you have different tabs for
learning and for the community which you
can go and check out and see what there
is but what we're going to focus on
right now is going into installs now as
you can see i already have a version of
unity which is
2020.1.2 f
1.
so
maybe you're from the future and you
have a better version or a more
uh or a newer version and in order to
add a new version you simply click right
here on the app so when you click on add
it gives you a different options to
download unity now as you can see you
have recommended releases you have
official releases and you have pre
releases now what should you choose
well personally me i like to choose the
official releases because
they are usually the least buggy there
is the recommended release which is also
not bad and there are the prerelease
pre-releases and now pre-releases are
not always that buggy but sometimes you
may encounter um
not very good performances during play
or during
game creation
they are not that common but i
personally prefer the official releases
so go ahead and choose one of them let's
choose the official release of
2020.1.10f
and let's click on next now this should
take you to another
modules to your installation window and
what we have here
is bunch of add-ons and
uses
for the
unity so for example you have android
build which will help you build games
for android you have linux build support
and mac and so on and so forth you also
have the documentation which i recommend
you download and you have the language
pack which if you have some kind of
different language chinese or korean i'm
not sure what those are you can also
check one of them and download that but
most importantly is you have to check
this developer tool which is microsoft
visual studio community 2019 maybe you
have a newer version
so this is absolutely a must because we
will be using the visual studio to code
all of our games so go ahead click on
those and click on next and the download
should start right here well you have a
box similar to this one and with a
little blue bar up here waiting to
finish the download so
now i'm going to introduce you to your
challenge and this is your challenge for
today so you need to download unity and
visual studio so first of all go ahead
and download unity hub then download
unity's latest release
and make sure you also download visual
studio with
unity so go ahead and do the challenge
and i'll see you in the next video
[Music]
welcome back my favorite game developers
i've created this video in order to help
you maximize
your learning potential in this course
so let's talk about the few things that
you will need in order to do that
first thing we have the q a
and what is the q a well it's a place on
udemy where you can actually ask me any
question that you stumble upon so if you
find yourself
in a certain video and you're not able
to complete the task at hand or you're
finding something very hard and you
can't understand it you always have the
q and a right here under each video
here you can first of all search for
your question maybe someone has already
asked the question and he and you can
find the answer
right under there
and if if you don't find the answer you
can always ask a new question so first
thing you'll need is the
question title make sure it's very
precise and
to make it easier on me and maybe other
people in the community make sure that
you always add as much precision and
make your question as clear as possible
so add code to it some people might use
this code and and to try it out in their
own game and see what's wrong you can
add images of certain errors and make
sure that you for example maybe make the
important words italic make sure that
your question is as concise and precise
as possible
and finally
if you do find or you can always go back
and lead the question if you find the
answer or you can edit and if you do
edit your question make sure to add
these solved
in the title so if you find that your
question has been solved and and has
been answered satisfactorily
make sure that you add in the question
titled these
words right here solved and this will
not only help me to know which questions
still haven't been solved it will also
help other game developers just like you
find the answers to their questions and
find them solved in the q and a
great
next thing let's talk about the
challenge slides so you've already
encountered your first challenge slide
and this is your challenges slide so
whenever you see this slide you need to
pause the video and do the challenge on
it it's a much better way to learn and
doing
is always better than watching in my
book so whenever you see the challenge
screen know that it's a great
opportunity to go out and try to tackle
the task at hand and the reason i
created these challenges is for you to
get as much benefit from the course as
you possibly can
i've personally tried over 10 courses
where the instructor simply goes through
the motions and at the end of the course
i had created a game with the instructor
but i haven't learned anything and i
felt i would never be able to replicate
any of it the challenges give you the
opportunity to try make a mistake and
get stuck trying to solve the problem
and even if you can't figure it out if
you have no idea how to do the challenge
try even even if you cannot complete the
challenge when i complete the challenge
after you've tried it will be in
ingrained in your brain and next time
you see the problem you'll remember the
mistakes you made and how not to do them
again trust me this is the best way to
learn and will keep you active as we
work through the game together so next
thing i want to talk about is the course
structure so the first section which we
are currently on will be the
introduction and the setup where i will
introduce you to unity if you're new to
it and introduce you to
the visual studio and why we'll use it
we'll actually also create our first
code and our first script which is very
exciting
the second
section will be the magic game cube okay
so and it's a cube that is in 2d which
makes it magic
and it basically will cover the c sharp
and unity basics we'll talk about the
basics of c sharp and the tools that
we'll need for our coding later on and
the basics of unity and everything that
we need to understand
from collisions to rigid bodies to
physics in unity and so on and so forth
now the third sex section is where
things will get very interesting and
it's our project which is castle
conquest to d and in this in the section
three we're going to be setting up our
world we're going to be creating our
tile sets we're going to be creating our
world adding collisions to that world
and adding our player
but not so fast because in section 4
we're going to be adding our conqueror
and we may have we may introduce our
conqueror in the section 3 but in
section 4 we're actually going to give
him the abilities to jump to run to have
different animation and so on and so
forth now in section 5 is where things
get a bit scary because we're adding
enemies and bombs so now our player is
no longer safe he will have to
fight off enemies and he will have to
avoid bombs along the way as he tries to
conquer the castle
and in section six we'll uh start
controlling our game so we'll be adding
a score we'll be adding lives we'll be
adding multiple levels to our game and
everything that goes on with it will
actually also be adding a lot of sound
effects and make our game much cooler
and finally in section seven we'll have
the bonus section and i've created this
section
i actually added this section on because
all the core game mechanics will be in
the
first uh fourth section but the seventh
the last section or the bonus section
will be where we tweak things a bit and
just
for the fun of it make our game a bit
more exciting and more fun so
make sure to always check out the
resources that are next to each video if
you find them there i will be linking
the
documentations to unity i will be
linking changes to our code and the
different things that may help you in
the current video and finally as a final
note
i just want to say that if you put the
extra effort into this course you will
get out of it much more than you paid
and that really is my goal is to leave
you as an expert problem solver and a
good game developer with lots of tricks
up their sleeves and
maybe even become a friend so i'll see
you in the next video
[Music]
so welcome back to another video
let's see what is unity so unity is a
cross-platform game engine developed
developed by unity technologies we use
unity to develop our game so what does
cross platform means it means that we
can use it on different platforms and
it's a game engine and what game engine
is it's a environment for us to develop
games and add physics and add different
things to create our game so let's check
out what unity actually looks like and
i'll explain a couple of things on it so
this is unity first of all we have this
toolbar right here
up above everything and this provides
access to the most essential working
features on the left we
it contains the basic tools for
manipulating the scene view and the game
object within it
in the center we have the play the pause
and the step control button and the
buttons on the right give you access to
the unity collaborate unity cloud
service and unity account
and will not get in much into that on
the right side of those we have the
layer visibility unit
menu
and we have the editor which provides
some alternative layouts for the editor
window and allows you to save your own
custom layouts so if you don't have the
same layout as i do you can simply click
right here on layout and you can choose
the default layout and this is the
default player that we have
it's the projects right here and
inspector and everything next thing
we'll talk about the hierarchy window
right here it's a hierarchical text
representation of every game object in
our scene so each item in the scene has
an entry in the hierarchy so the two
windows are inherently linked the next
hierarchy reveals the structure of how
game objects attach to each other so
right here we have the sample scene
and if we click on that we have the main
camera under it and if we add another
game object it will also show up right
here
and here is the inspector as you can see
on the right this is the window
inspector and it gives it allows you to
view and edit all the properties of the
currently selected game object so if we
don't select the game object we don't
see anything when we click on main
camera we have these different windows
right here and the layouts and content
contents of the inspector window change
each time you select a different game
object so now we don't have a different
game object so we'll just settle for the
camera
next then we have is this scene view
right here and the scene view allows you
to visualize and navigate and edit your
scene the scene view can show you either
a 3d perspective or a 2d perspective
depending on the type of project that
you are using so in scores we'll be
using the 2d project
view but you can also right here click
on the 2d button and it will go 3d
so as you can see we have this 3d view
but we won't be needing it we'll simply
go into the 2d
mode
and finally i want to talk about the
project window right here which displays
your library and assets that are
available to use in your project so when
you import assets
into your project they will appear right
here so for example for now we don't
have any assets we only have the scenes
folder and inside the scenes folder we
have this sample folder so this is a
quick overview of unity and what all
those panels and gadgets are we will of
course delve deeper into them as we go
through the course but now i want to
talk about
the something very important and that is
the visual studio so what is visual
studio well visual studio is a microsoft
visual studio
it's used well it's developed by
microsoft and it's an ide and ide is an
integrated development environment and
what it does it actually if we ask
meaning visual studio will help us write
the code used to manipulate game objects
in the unity
using something called scripts so how to
use unity with visual studio so we need
a way for unity and visual studio to
communicate but they do not simply do
that
we need to add something to it called
the dot cs file and that is our scripts
and those scripts allow we actually take
those scripts we attach them to game
objects and using those scripts we'll be
able to add behavior to different kinds
of game objects and we'll see that very
very soon so let's go into visual studio
and see what it's all about this is
visual studio and maybe the first time
you open it up you'll have different
panels right here on the right and
different windows right here on the left
feel free to close all of them
and don't worry about what happens next
of course you won't have this the first
time you start up visual studio but
you'll see it soon enough and i'll just
introduce you to a couple of line of
codes right here so let's zoom in just a
bit
and right here on the top you can see
that we are using system collections we
are using system collection collections
generic and most importantly we are
using unity engine now what are all of
those well those are called name spaces
and
basically these are libraries that give
us the opportunity to use
different kinds of code so for example
unity engine which we've added right
here allows us to use the start method
and the update method and different
engines
to create games and make it much easier
and we simply right here using unity
engine and it saves us a lot of code and
gives us the entire library to use
next thing we have the public class
class name and this is the actually the
class name which should be right here it
will be the script that we've talked
about and it will be attached to a game
object
and it will encompass all of the code
that will change the behavior of our
game object inside of our game and mono
behavior is a base class and it's
actually these two mean that it inherits
from the mono behavior which allows it
to use uh different kinds of
manipulations and engine and physics and
so on and so forth
and next thing we have is the start and
of above it is something called the
comment so whenever you write code and
add these two
lines right here it will comment things
out and comments actually don't get
executed in the gold the code
code the code and they are perfectly
saved so it start start is called before
the first frame update so as soon as our
game starts
the start method and this is called a
method will start to execute next thing
we have the update and the update is
called once per frame
so
every frame that we have in our game the
update is called so start is typically
used to
give the initial
properties or configurations to certain
objects and the update is used
for
objects that maybe are moving or change
every frame so if we have a car for
example and start we can give it the
color the name the speed at which it can
go and an update will be moving the car
will be making the car jump will be
making the car
go faster maybe increase its speed so
you get the basic idea of visual studio
and now it's time for your challenge and
your challenges to go make a mess so
open unity create a project and if you
don't know how to create a project
we'll do that in the next video
and when you're finished after you go
make a mess go to the next video and
we'll make our first code and get
started so i'll see you in the next
video
[Music]
welcome back my fellow game developers
in this video we are going to be
creating our first code and our first
game object so as you can see right here
we have a game object called hello world
in anaha in our hierarchy it's present
right here in our scene although we
don't see it very well and we have this
script right here attached to it we've
also created the script right here in
our project
and in console if we click on play
we actually get a message that displays
hello michelle which is me but in your
case it will it's going to be displaying
your name
so i'm very excited for this video
because it's our first
delve into unity world so i hope you
enjoyed the video and i'll see you in
just a bit
okay so first thing we're going to do is
we're going to open up unity hub and
currently you have no projects here
which will change in just a bit first
thing we'll do is click on new right
here
and we'll need to choose a template for
our game so we'll be creating a 2d game
not a 3d and these are different options
also
for different project types next thing
we'll need to add a project name feel
free to name it whatever you want we'll
be calling it for now the hello world
the project
and make sure that you choose a location
for your unity
project so we'll click on this one
and let's go back and save it inside of
the unity projects so select the folder
and now we have a location for our game
you need to do all you need to do right
now is click on create so click on
create
and unity will start to create your
project and i will not bore you with the
uh
waiting here i'll use the magic of
editing and we'll simply jump into the
project so see you in a bit
welcome back so i hope your project also
finished setting up so this is our scene
if you don't have this kind of scene as
i've told you you can always go to
layout and choose the default layout and
we'll have the same layout both of us
so before we start let's
first of all add something called the
console and as you can see even before
we start anything we have this console
window right here and what this does is
it shows us the messages and we're going
to use this console window to see the
things that will print from our code and
if you don't have it you can simply go
up here in window click on it
and just above here you can see on the
general
we'll have the console so click on it a
window should a appear and you can dock
it wherever you want i'm going to dock
it right here next to projects another
thing i want to talk about is in the
wherever you've saved your uh project
i've saved it in d unity projects and
hello world so as you can see we have
different folders right here we have the
assets which hold our scenes and
everything that we create in projects
you can see the assets and project
assets right here
we also have the library which
automatically
is created every time we enter a project
we have logs we have packages we have
project settings all our though all of
those are details that will not get into
too much and the temporary folder which
we'll
discuss later on in the magic cube to
the
game so let's go back into unity and in
here we are going to be creating our
script so let's right click in here
and let's go into create and in create
we can actually create multiple things
as you can see we'll do a couple of them
in our project but for now let's simply
create a c-sharp script so click on that
and before you do anything so
now don't do anything
leave everything
you will need to make sure that whenever
you name a script that you do it with
precision because it will cause error
later on if you want to try to rename
your script so make sure you name it
correctly from the get go so we'll name
this
hello
world without any spaces and click on
enter when you're sure that you have
decided on the name of the script so
click on enter and i'll tell you why in
just a bit so as you can see
we have something right here in the
inspector and it took a bit of time and
it's because unity needs to compile the
code right here and you can actually see
the code in the inspector and why i told
you it's so crucial to make sure that
the name of the
script right here is
defined before we click on enter it's b
is because
it is going to be the name of our class
so if you change the name of our script
right here the class name won't change
and there will be an error where unit or
the visual studio will not be able to
find the correct script in the project
and this will cause errors so to avoid
that simply make sure that you name your
script correctly and precisely from the
get go now what should we do next it's
very simple you simply double click on
hello world
and the visual studio should open up
and as you can see right here this is
what we've described a couple of
maybe in the previous video
so what are we going to do in here we
are simply going to print something to
our console and we'll do that inside of
start so let's go ahead and print
so as you can see immediately visual
studio our great friend starts to help
us and it gives us suggestion for what
we want to use so we
write the print it gives us the
suggestion and now you can simply click
on tab and it will finish it for you
and now we open up our brackets and we
can see that visual studio again helps
us and it tells us that we need to add a
object message inside of here and that
object message is going to be a string
we'll talk about strings later but for
now string is a
string of characters that we put inside
of these two quotes right here so let's
go ahead and add these two quotes again
and now we write inside of these two
quotes hello
world so
is that enough well actually no because
if you see right here we have this
squiggly red line and if we hover over
it it tells us that it expects
a
symbol which is this one and every line
of code in c sharp you have to add this
semicolon right here so save that
and now because we've put it inside of
start as soon as we start our game this
message should be printed on the console
so let's try that we go back into unity
and we go into console but if we click
on play
as you can see nothing is being
displayed on our screen
why is that because it's not enough just
to create a script you actually need to
attach it to an object so let's create
an object and the way we do that we
simply go into our hierarchy we right
click on here
and we can create a empty game object
click on that and now we have a game
object let's go ahead we can change the
name of that game object we'll call it
um
let's call it
hello
world
object
click on enter and below it you can see
that it's we have the transform and this
transform tells us the position of our
game object in the world
and up here we have the tools to
manipulate so if you click on this tool
you can actually put the object up or
drag the object down
take it to the left or to the right and
put it anywhere we want
and currently we cannot see we don't
have anything to represent our game
object we simply have its coordinates
and its transform so let's attach the
script to this game object to do that we
simply click on the
script and drag it into the hierarchy
into the hello world
object so if you click on hello world
object right here you can see that it
has a script
just below the transform attached to it
and now if we click on play
in the console we can see that we have
hello world
congratulations you've just written your
first code and you've just used your
first game object to display something
to the console great and now it's time
for your challenge and your challenge is
going to print your own name so instead
of hello world you'll need to print your
own name
so change hello world to hello
and and
instead of those three dots of course
it's going to be your own name
i'll give you a couple of hints so add
your name inside of the dots
save visual studio always remember to
save visual studio using ctrl s
go to unity and click on play
and check your console so
make sure it works
pause the video right now and go do the
challenge
okay welcome back how did you get around
with that i hope you tried your best in
that challenge
let's go into visual studio and instead
of world i'm going to delete that and
i'll put my own name which is
michel so hello michelle
and we'll just add an exclamation or
three exclamation points for the
dramatic effect
and to make sure that you've saved your
project i mean your script when you look
up right here you can see that it has a
small asterisk attack asterisk astrix
attached to it and to save that you
click on and that means it hasn't been
saved so if you hold ctrl s click on
control s you can see that the asterisk
asterix disappears and that means that
the script has been saved go back into
unity
you can see that there is an asterisk
right here also next to the sample scene
so save that
and now if we go to console you can see
right here that we have this button
clear or you if you click down you can
see that we can click on play you can
remove that feel free it doesn't matter
we'll just remove it to see the changes
that happen and now if we click on play
we will have hello michelle
or hello whatever your name is my fellow
student and
that is all so clear that let's try that
again click on play
and hello michelle hello my favorite
game developers i hope you enjoyed the
video and i'll see you in the next one
[Music]
welcome back my fellow game developers
in this video we are going to be
learning everything about
version control source tree
and creating repositories of our
projects so as you can see right here
we've created a new project we started
our big project which is cyberspy 2087
and we've downloaded sourcetree we now
have a couple of comments in here and we
actually reverted something we've
created our initial commit added a cube
reverted it we can actually reverse this
commit again so click on yes as you can
see we can go back to unity reload and
we have our cube right here we will be
learning everything in my new detail so
give me your entire concentration this
is very important it's an extremely
helpful
video or lesson and will stay with you
forever as long as you are committed to
becoming a professional
programmer or game developer so let's
not waste any more time and let's get
started
okay so version control
let me put on my laser version control
it's hard to learn it's even harder to
teach but i'll try to keep it as simple
as possible and when you get the hang of
it trust me it's very simple and easy to
use plus it's an indispensable skill
that you need to learn if you are
looking to become a professional
game developer or even a professional
programmer so let's get started with
what is it
first of all it's a system that is
responsible for managing changes to
computer programs so this means that
whenever we create changes in our
programs we can actually save those
changes at each step of our project this
way we can first of all check what we
did we can create different kinds of
versions where we can go back and change
the things that we've created it allows
for a better
teamwork so for example let's say you
have four or five people working on the
same project but each one of them has a
different task that they need to create
so version control is a very good
way of handling all of this and why do
we need it well
why we we actually use it well we'll use
it to remember previous version of our
game and have more flexibility to
experiment
usually game development is
a
environment where you require a lot of
experimentations for example you want to
add
some kind of
property to some kind of game object and
maybe it breaks your entire project so
you want to always have a previous
version of your project before adding
this game breaking mechanic so you can
always go back and start fresh from
there so this is extremely important
especially for game developers that
always need to be experimenting with new
ideas and things in their games and
projects
and how are we going to use it well we
are going to be using something called
sourcetree and this is version control
it allows us to create different
versions and it's first of all it's for
free it's very easy for beginners
very flexible and it has a very simple
interface that we can use as beginners
so let's go ahead and download
sourcetree let me show you where we can
do that
if you open up
chrome or any browser that you have
simply go to google and write in here
download source tree you should find a
link right here and it should be the
source tree app when you click on it you
go right here to their website if you
scroll up you can see that you have the
option to download for windows but if
you are on a mac make sure that you
click on here and you download source 3
for mac os or it will not work for you
so if you have a mac download the mac
version if you have
a windows download the windows version
simple enough now when you finish
downloading you should get this file
right here and when you double click on
it you should start the installation now
because i already have source 3 i will
not be installing it another time i will
just take you through the process of
actually installing it ok so this is the
first window that will pop up for you
first of all you need to agree to the
license of course and you can maybe turn
this off if you don't want any emails
your way from
sourcetree and etc atlasia
next thing you need to do is you need to
create an account on atlasian you can go
to atlasian and atlasian is the parent
company of sourcetree you can go ahead
and create an account there or you can
use an existing account if you already
have a gmail i personally created one
using gmail it's much faster it's way
easier and they don't spam you with a
lot of emails
next thing in here we are going to
connect it to an account now this is of
course
we will not be doing this this is if you
want to host your code on a certain
website like github or bitbucket we will
not be doing that so you can simply
click here on skip setup
finally while installing sourcetree will
tell you that it is unable to locate git
so in order to complete this simply
click on download an embedded version of
git
and continue on
and then it may also ask you for
something called a mercurial now
mercurial is a different system just
like git it allows us to
save different versions of our project
we will not be using mercurial so you
can simply click on i don't want to
download or i don't want to use
mercurial and this should be it
when you finish installing you should
have this right here
and your well this window right here
when you start sourcetree if you don't
simply click right here on create and
you should get
this
window now this is where we actually
create our repository and in here you
can see that we have the destination
path the name and the type of version
control that we want to use of course
we'll be using the git we also have the
option to create an account but as i've
told you we're keeping things very
simple it's our first time so we will
not be creating any account
so in here we are going to choose
which what is the destination path of
our repository so what what is the
project that we are actually going to be
creating a repository for and subsequent
versions of
well let's create our first project that
we are going to be using
so in here let's open up the unity
hub and as you can see we already have
hello world that we've done in a
previous video let's click on new
and let's make sure it's a 3d
project and this is going to be our
cyber
spy
2087.
let's go ahead and create this project
so click on create
and i of course always using my magic of
editing in order to speed up this
process i'll see you on the other side
okay welcome back so i hope everything
worked out for you so now we have a new
project which is cyber spy
2087 so now that we have our project
created we can actually go ahead and get
started with creating a repository now
if we go back into our source tree right
here we can click on browse
and we can actually go ahead into unity
projects and you can see that and we
have a hello world and we have a cyber
spy
2087. so let's select this folder it
will create a repository under this name
and if we hit create
it will ask a problem don't worry about
it click on yes
and voila now we have actually started
creating a repository you have the
staged files right here you have
different kind of knobs you don't need
to worry about any of them for now just
focus on the staged files unstaged files
and commit up here now if we scroll down
in these unstaged files you can see that
most of them are from the library
we scroll down to the end we can see
some of them are tamper temp
or temporary we can see also that we
have project settings and these are all
the files that we have
for our project we also have assets in
here for unity in the scenes for example
so this is a repository which is a
version of our current project
now
the problem here is as you can see there
are a ton and ton of files
and we will not be needing all of them
well actually we'll need
almost none of them we will need only a
certain kind of files
so we want to be ignoring the library
and the temporary temporary files why is
that well let me show you by opening up
the
directory of our current project
okay so this is cyber spy 2087's
directory inside of unity project as you
can see up here so we have the assets
the library logs packages etc and etc
now what is the temporary folder and
what is the library folder and why don't
we actually need them so temporary is
just a way for unity to open up faster
whenever we start the project and it's
always created whenever we open a
project so for example if i go into
unity right here and i actually close it
you'll see that the temporary file
will disappear and even if we delete the
library right now so let's go ahead and
delete this library entirely
if we go back into our unity hub and
open up cyberspy 2087
as you can see right here you saw that
the library has been created again and
the temporary folder has also been
created so of course the project should
take a bit more time now to open up but
this is evidence that a library and the
temporary folders are not necessary for
us to always commit and stage
and what do i mean by stage so whenever
we stage our folders
we actually create a commit from them
and a version of them and library takes
up a lot of space as you can see if we
scroll down it takes up most of the
space and we don't want any of them at
all
so
how should we proceed well we can
actually ignore all of the folders that
are under the library by simply going
and choosing any of the folders that
have library on them
right click on it
and in here you can see that we have the
option to ignore one of them so click on
ignore
and in here you have the option to
ignore this exact file name ignore all
files with this extension or you can
ignore everything beneath a library and
this is what we want so click on ok
and as you can see everything under
library has now been ignored so we
cannot stage it so we cannot save it to
our newer version and if you scroll up
you might have noticed that we have a
new folder in here that is the dot git
ignore and when we click on it on the
right you can see that it has the
library in it and if we double click on
it we can actually open it up in our
notepad and in here we can add the
different files that we also want to
ignore so
what are the files that we want to
ignore well there are a ton and ton of
files but thankfully somebody has
actually gone through all these files
and created a list of everything that we
can ignore whenever creating version
controls or versions of our project
and in order to find that file you can
go again into google our dear friend
go ahead and search dot get ignore unity
and you should have this link right here
for the github.com
it's it will be hosted on github if you
open up this link it will take you right
here so this is the dot git ignore and
it's the unity dot get ignore and these
are all the files that we can ignore
when creating versions of our
project you can click on raw right here
and it will open up this window or this
tab
let's go ahead and select all of them by
clicking on control a
we will copy all of this using ctrl c
and we are going to paste it in here in
our dot git ignore notepad
and now we have this git ignore
notepad filled with all the files that
we will not use for our repository we
will save that using ctrl s
and now back in unity or i mean back in
source tree you can see that when we hit
the get ignore everything is ignored we
will stage all of that
and when we stage all of that you can
see that these are the files that are
going to be committed and these will be
our initial commitment or our initial
repository version of the project and
usually whenever you create your initial
commit we call this the initial
you can capitalize it
the initial
oops
initial
commit
and we click on commit right here
so now if you look on the left you can
see that we have branches under here and
we have the
master branch
congratulations we have created our
first commitment
very nice now
let me just show you how we will move
further down the line even though this
video has been long enough but i think
we need to
get a proper
foundation for sourcetree and version
control as we move through our project
so let's say we are in our project right
here
and let's go ahead and create some kind
of cubes 3d object
right click in the hierarchy 3d object
create a cube and now we have a cube
let's scale it up a bit so scale it on
the x the y and the z
great so now we have a cube in our scene
and now if we go into sourcetree let's
save that before we go
and it needs to save it to a certain
scene so let's inside of scenes this
will be our sample scene sure sample
scene yes replace it so we have this
sample scene
back in sourcetree
wait for it a bit and you can see that
we have uncommitted changes so if we
click on them you can see that the
unstaged files are changes inside of the
scenes which is the sample scene and
here you can look in detail what we've
created now it's a bit
weird right here but if you look closely
you can see that we've created box
collider and basically this represents
the cube that we've added to our scene
so let's go ahead and stage all of that
we can click on comment right here
and name this added a cube
click on commit
and now in our master branch you can see
that we have an initial commit which
didn't have any cube and now in our
added cube we've well added a
cube so congratulations
and
as a final note
uh this may look a bit cumbersome this
may look a bit weird but don't be afraid
this is very simple and more importantly
it's extremely important for us to
understand as we move through our
project create version
versions of it and if we ever make a
mistake we can actually go back by right
clicking in here and reversing the
commit
and yes we can reverse the commit if we
go back into unity it will ask us for a
reload we wrote we reload and
now we don't have the cube or any game
breaking mechanic that we've added along
the way and now
it's time for your challenge and your
challenge is going to be to download and
set up sourcetree and
the ignore file so
download sourcetree install and set up
everything create your 3d project in
unity hub set up a repository for it in
sourcetree ignore the library files get
the dot ignore file and add it to your
repository create your first commit and
then create your second commit you can
even go ahead and try to maybe play
around with a couple of things add a
cube reverse the commit see what happens
get comfortable with sourcetree and
if you're having a bit of trouble you
can pause the video on this list of
things that you need to create
and you can also always go back and
watch the video and see how i made
everything and follow along with me step
by step so i'll see you
in just a bit
so
in the next video we are going to be
setting up our world creating various
materials and starting our big cyber spy
2087 project so i'll see you there
hey
congratulations you are almost around 20
to 25
down the course you know that there are
very few people that have made it that
far and you are one of those people
congratulations i hope you're having fun
so let's not waste any more time and
let's continue on with our journey
[Music]
welcome back everyone to another amazing
video in this video we are going to be
printing things to our console
but not using print but using debug.log
which will enable us to add warnings and
errors and we'll do that using a script
that we've created
in our project we'll be adding it to our
magic cube so as you can see in
inspector we have this script attached
to it right now and
we'll be creating some code very scary
but not too much and finally we'll be
committing our project so let's get
started
okay so
first thing you need is this console
window if you don't see it just yet you
can simply go into window
and go into
our
where is it so it's in general
console
simply click on it and you should get
this console window it would
be up here somewhere you can simply dock
it next to our project okay great
if you look closely you can see that we
have click clear collapse so clear what
it does it is it clears all of our
console i've checked it on clear upon
play
we have collapse which means that when
we have several messages that are the
same it simply collect com
collapses them into a single message and
here on the right we can see that we
have
three buttons that we can check and and
uncheck one of them is messages
the middle one is the warnings and on
the right we have the errors that's the
scariest messages we can get
okay great so
next we're going to create our c-sharp
script you are already familiar a bit
with it so go to our project right click
go to create and click on c-sharp script
whenever you want to name something like
this make sure that you
name it correctly the first time we've
talked about this so what are we going
to name it let's simply name this cube
click on enter now we have our cube
script excellent
so we can open this up by doubly
clicking on it
and visual studio will compile
waiting for it
anytime now
loading solutions
and we should have everything in
okay great
so as you can see we already have some
code in here
we don't we won't be worrying about that
what we will be doing is we'll go into
our start method
and inside we're going to be printing to
our console now if you went through the
first section you may realize that we
used print but now we're going to use
debug
and as always visual studio is extremely
helpful so db debug
click on tab it will finish it for you
dot log and open up the brackets and as
i've said previously we've used print
but now we're using debug why is that
well debug gives us more flexibility and
control and it's technically better and
it gives us better habits for future
coding so what is the message we're
going to write in here the message will
be
hello
everyone
everyone
i'm
printing
from
debug
okay
put a semicolon there and now
we save it put a ctrl s
go back into unity
but now if we click on play
we should not see anything and why is
that we only see our square in the scene
but nothing is printing to the console
that's because we haven't attached our
script to anything so let's go ahead and
attach it to our magic cube
save that and now when we click on play
and go into console we should have hello
everyone i'm printing to debug
excellent okay
now it's time for your challenge
and you will need to add a couple of
lines so first thing you'll need to add
two messages that display on the console
telling to the player to press a certain
arrow key
next you'll need to add one warning
message
and finally you'll need to add one error
log message and i'll i'm going to be a
bit helpful with you here if we go into
visual studio
i will give you a hand so if we click on
debug if we dot log we can see that we
have log error and log warning so go
ahead and get on with that challenge
welcome back how did you do that it's
not a very hard challenge but it might
be tricky if you're just starting off so
let's create our debug dot
log
and
we'll change this here will tell the
player
if you
press
the up arrow you'll
jump
and below we're right
if you
press the
right arrow
you'll
move okay
and now
we'll need to create a warning so let's
go ahead and do that dot log
warning and simply when you open the
brackets you can
click anything if
you press the
space
nothing happens
and finally our error which will be
debug.log
error
and inside of it what should we write
if you
smash the keyboard
nothing happens
you just cry
okay save that
key keyboard keyboard okay nothing
happens you just cry save that go back
into unity everything should be compiled
and if we click on play
hello okay great so if you press the up
arrow you'll jump if you press the right
arrow your move and we have a warning
that if you press the space nothing will
happen and an error if you smash the
keyboard nothing happens you just cry
great i hope you enjoyed this oh and one
last step click on play
save everything go into source 3 because
we have uncommitted changes now i don't
think i'll be doing this every single
video but you should know that whenever
we make changes to our game we should
always
commit them so stage all
click on commit here on the far left
corner
and what should we call this we'll call
this
adding
a script with
debug
debug
dot log
inside okay great
commit that
and we have it in our master branch and
i'll see you in the next video
[Music]
welcome back everyone to another video
today we are going to learn about
variables so we'll learn what variables
are
we will learn how we declare those
variables and we are going to learn
how these variables make our code more
flexible so as you can see here we have
some different kind of messages because
we've integrated those variables into
our debug log
and here in our code we see that we have
three new variables one is integer the
second one is a string and we have also
a float and we've added those
variables into our debug.log so let's
not waste any time and let's get started
so variables what are variables well we
can
think of variables like boxes you have a
box
that we call lives and we want to put
some
information or something inside that box
to hold it
so we put a 3 inside of it
and what is that 3 well it's an integer
number
how do we write that in code well we
have this way of writing it it's an int
which means an integer lives equals
three but what do these
even mean well first of all we have the
type
of the variable we have the type here is
integer
we have the name of our variable which
is lives
and by well it's a common
tradition in coding if you like
of naming the variable
where the first letter will never be be
capital and all other words inside of
the
variable name will be capitalized and
finally we have the data and the data
should reflect the type that we give it
so what other types do we have we have
float
variables for example if you want to
talk about velocity and velocity has can
be
4.8 and the way we write it is we
write float velocity
and 4.8 f whenever we want to make a
float variable we add f2 to the end of
it
then we have boolean and as you can see
here we've named it is
dead where the first
word of is is not capitalized while the
second one is capitalized and a bull or
a boolean can be either true or it can
be false
and we also have
a string variable a string valuable
means that it has
it's a string of characters
or for example here we have the box
called my name as you can see also the
second word is capitalized we write
string my name equals michel which is me
and we put it inside of a box and now we
have a variable of string okay great so
how are we going to translate that into
our personal code we're gonna make this
well what actually happens is variables
make our code more flexible they help us
manipulate the code in a better way
let's demonstrate that let's go back
let's go back into our visual studio and
let's go ahead and create a variable so
first thing first if we create a
variable inside of start right here we
can only use it inside of start but if
we write it outside of our start method
we can use it anywhere we wish in our
code so let's do that first
so what variable should we use well
let's create an integer variable so
let's say that we have an integer
we'll name this integer
number
of
times and we'll assign it a value of
let's say five
okay
save that and as you can see
it's black and white or it's a bit
transparent that means that we still
haven't used it and now let's use it
so if we go ahead in debug.log it says
if you press the right arrow you'll move
so let's go ahead and add something to
it to add a variable we simply do the
following click on space
close the bracket or the
little column in here and then we write
plus
we write number and visual studio as
always this is our best friend and helps
us
simply click on tab it finishes
and we save that and now we have a
variable inside of our debug let's see
what happens in
i mean in unity
let's go ahead clear all of this and
click on play
and as you can see here in our message
if you press the right arrow five you'll
move we should have added five times but
you get the picture
so now let's add a string variable so
let's go ahead and click right here
string
we'll
name this
name
of the
key
and our string will be
let's say
space
so space
okay so space
and now we want to add it to the warning
for example so instead of writing space
here
we'll simply
open this and close it on the other side
write plus
and name of the key
and then another plus and now we have a
string variable inside of our log
warning we save that we go back into
unity and when we click on play
we should see here that it's space
well that wasn't very helpful because we
don't know if it worked so let's change
this from space to
enter let's make this also all
capitalized save that
go back into unity
click on play and this should change to
enter
and it did
so you can begin to see how flexible
using variable makes our code so instead
of going and looking for every single
name we can simply add a variable and
change it from the top and all
subsequent uses of it and our code will
change so
what now well i think you know because
it's time for your challenge and your
challenge is to create your own variable
so you need to create a variable of type
string and use it inside
inside of the debug.log which we already
did so go ahead and make your own
variable
we are going to create a variable of
type integer and use it in one of the
warnings
and finally we're going to create a
float and use it inside of the error
logs so pause the video right now and go
try and do your best don't worry about
messing things up that's why we have
version control
i'll see you in a second
okay welcome back so how did you get on
with that it shouldn't be too hard
so let's go ahead we've created our
string we've created our integer now
it's time for our float variable so
let's go ahead and create a float what
should we call this
we'll call this um
at a speed
we'll simply call this speed
a speed of
breaking and will make this value
four point
or wait we'll make this 6.94
okay great
and
i've made a mistake here it should be
6.94 f
okay so let's go ahead and add it here
in our debug.log error so if you smash
the keyboard let's look here
at
a speed
of
let's
simply add this and what should we write
here
speed of breaking
click another plus
and now if we go back into
unity click on play
it should tell us that if you smash the
keyboard at a speed of 6.94
nothing happens you just cry
okay i hope you enjoyed the video i know
that the variables and the messages in
the debug log don't make a lot of sense
right now but you will see that later on
it will be very important so
i'll see you in the next video
[Music]
welcome back my fellow game developers
in this video we are going to be
responding to our players input
and that will happen how well if we
click on play right now we don't see any
messages until we press the up arrow it
get it gives us a message that tells us
up arrow key was pressed and if we press
the left arrow it tells us left arrow
key got pressed right arrow
and the down arrow and we did that using
using some magic code
very scary but don't worry about it i
will take you step by step and in fact
in this video you are going to do that
not me so let's get started
okay so as the title of this video
suggests we are going to be getting our
players input and for that we'll use for
example the up arrow the right arrow or
the left arrow and based on that we are
going to print something on our console
but in this video we'll be doing
something different because
my goal in this course is not to
just
show you how to create a game i want you
to become
an expert problem solver so in this
video i'm going to tell you the problem
that we have and i will take you step by
step on how
i usually solve my problems
so first thing we're going to do is
we're going to think of our problem
so the main problem is we need to get
our player's input
from a certain key that he pressed he or
she or she of course presses
so the key words to look for are input
and key
and whenever we face something that we
don't know
unity has a great documentation site
so we can actually google it
so we go into google
and we simply write input unity
we get all these search results but what
we are looking for is the documentation
which is scripting api input unity
if we click on that it takes us to
this documentation so we see that we
have input we have description you can
always read all the documentation
but you're of course
read it later you don't have to get
specific in every detail just a glance
over to see what it has
so as we scroll down and we know that we
need a key
that will tell us what key the player
pressed we can see that we have multiple
static methods in here and one of them
is called get key which returns true
while the user holds down the key
identified now as we've said our problem
is
doesn't consist of a player holding down
a key we only want to return something
or get a response from the player from
us from the game whenever a player
clicks
or presses a button doesn't hold down so
if we read below it we can see that
return true during the frame the user
starts pressing down the key identified
by name
this looks like something we could use
so we click on get key down and it takes
us yet to another
unity documentation and here is where we
begin to read our description which says
that it returns a true during the frame
the user starts pressing the down
identified by name great this is what we
need
and
even if you're if you don't know how to
actually code it if you scroll down just
a little bit you can see that we have
multiple examples of this
and here we have this amazing example
which tells us that they are actually
putting this get key down inside of
update and using something weird which
is an if
with some parentheses and i don't know
what that is it's so weird it's so
difficult
let's not trouble our heads with it
let's simply copy this
so we'll copy this
and of course we'll be explaining if
conditions later and we go back into our
visual studio and as they told us in the
example we will paste it inside of
update okay great so a small
i do a small explanation of what we're
actually doing here so if condition
works as it says if
anything inside of
this place here
inside of these two brackets is true
we will execute any code inside of these
two curly brackets
don't worry about if conditions if
you're new to them we'll be explaining
them in in more
in-depth in later videos but for now
paste this inside of update save it and
let's go back into unity
click on play
now we press the space bar
space key was pressed pressed pressed
and pressed
okay great but as we've said we are not
looking for the space we are actually
looking for the arrow so how are we
going to do that well we hope that
our good friend visual studio will help
and it will
so
if we double click here on space and
delete it
delete the little point and if we click
it again as we see it gives us a lot a
lot of options
so what are we looking for we're looking
for the up arrow so let's write arrow
and voila it gives us all the options
that we can use and one of them is the
up arrow so simply click on tab and now
it should work when we press the up
arrow so let's
remove this and actually instead of
space
we write up
arrow
okay nope not
excuse me so save that
let's go back into unity
go back into unity clear all of that and
click on play
wait for it to compile and now if we
press the up arrow we should get up
arrow key was pressed
okay great one more thing i want to do
let's comment all of these out
and the way we do that is with two
backslashes just as
we have comments in here just so they
don't get in the way and now it's time
for your challenge and your challenge is
to finish the rest what do i mean by
finish the rest well now you have to
finish
if the player pushes the down arrow
and if the player pushes the left arrow
and then small extra challenge for those
of you
out there that are very motivated if the
player pushes the space bar even though
we've already done it i want to see how
you do it so pause the video right now
and get on with the challenge
okay welcome back how did you get on
with that
so
let's simply go ahead and copy this
there's no shame in copy pasting code
even though it's better to find a better
way to do that
so
what will we be using in here we'll be
using the
down
arrow
and we'll copy this also and save
ourselves as much time as possible so up
down arrow and in here we're going to
use
the left arrow
and also copy that
and just for the sake of being
even extra nerdy we'll make one for the
right arrow so right arrow
copy that
and here we'll simply write
arrow
let's make this
capital letter save that and now if we
go back to unity
and click on play all of this should
clear and now if we press the up arrow
we get up arrow key was pressed left
arrow left arrow key was pressed right
and down and everything is working fine
and before we go don't forget to commit
our changes don't worry about if i have
some extra changes here these were just
experiments so stage all
click on commit and we'll write here
[Music]
added
a couple
of player
inputs
okay so commit that everything is
working fine it's in our masters and
i'll see you in the next video
[Music]
welcome back my friends to another video
and this one will be using rigid bodies
and we'll be using box colliders
what how are we going to use them we'll
use them adding components and why are
we going to use them well because now
our cubes are not just images they
actually
fall and not only do they fall but they
get cut
using the platforms that we've created
so
let's not waste any more time and let's
get started
so now
if we click on play our cube doesn't do
anything interesting
and what we wanted is we want to at
least make it fall so how do we make
this cube fall and hence how do we add
the gravity to it and make it a physical
real object we do that using a rigid
body
and what is a rigid body well rigid body
control
allows us to control
an object's
position through physics simulation i
know it's a handful it's big words but
if you go to unity's documentations
which i have left you in the resources
you can actually read all about rigid
bodies
and rigid body object will be pulled
downwards by gravity without adding any
code which is amazing and exactly what
we need
so so if we go back into unity we can
actually go into our magic cube and if
we look here on the right to our
inspector we can see that we have a
transform we have a sprite renderer and
we have the cube so transform tells us
the position that our cube is at the
sprite renderer actually renders our
cube so if we turn it off
it goes away turn it back on it turns
back and the cube is our script so let's
make all of these smaller and we have
here this button which allows us to add
components so if we click on add
components
we can actually search for rigid body
and we have two rigid bodies one is
rigid body which is used for the 3d
world and the rigid body that we will
need which is rigid body 2d
click on rigid body to d
and now
we can see that we have a lot of options
and information and constraints and body
type and mass
don't worry about all of these
we won't be using all of them but if you
are interested
and you want to go deep into the rigid
body subject you can read all about them
in the unity documentation
one thing i will be glancing over is the
body type which we have dynamic
kinematic and static now later on we
will delve even deeper into these three
but for now what you need to understand
is that dynamic is when our
body is
subjected entirely to the physics world
around him kinematic is when our body is
not affected by gravity but could be
affected by other forces and static is
an object that does not move at all
whatever happens to him
so we need our cube to be for now
dynamic so we've added a rigid body
let's save that
and let's click on play and see what
happens if we click on play
our bad d or our magic cube goes down
and leaves our scene and we have no idea
where it went
it goes away into i don't know what's
called down there maybe hell or anything
but it disappears so
how are we going to hold it because for
now it's not that magic we'll do that
using colliders and what are colliders
what is a collider
a collider makes it possible for objects
to interact and hence collide with each
other so whenever our collider or or
whenever our body has a collider and it
touches another body that has a collider
they will
collide and stop each other
we'll use it to catch objects that are
following are falling because of gravity
so we're going to use this collider in
order to
catch the object that we have so let's
go back into unity
and close down this rigid body and add
another component and we can actually
search for collider
and as you can see we immediately have
tons of options we have box colliders we
have box colliders to the capsule
capsule to the circle circle to d so
because we're using our cube or square
we'll be using a box collider 2d which
is ultra simple
and as you can see we also have tons and
tons of options you can read all about
them i of course left it in the
resources
but one thing we need to focus on is
this is trigger and this will be useful
later on in the course but for now let's
just zoom in and see what we have
we can actually see our
box collider it's green it's a green
line all around our box but we cannot
see it right now
the way to see it is if we click here on
the edit collider
and we can actually make this collider
bigger make it this way and this way and
actually make it outside so this is the
colliders this is actually where our
object will be colliding with other
objects so let's reset all of that
and let's see what happens if we click
on play so exciting
and then
nothing happens why is that it's because
you have a challenge and your challenge
is to catch the falling cube don't worry
i won't leave you alone because first of
all you need to create another cube and
size it to platform size what do i mean
by that well you need to make our
platform
from
this end right here all the way to the
other end in order to catch our cue
so let's continue with the hints create
another cube and make it a platform
add a rigid body and don't forget to
change the rigid body type to static
and finally add a collider to our
platform and catch our cube so pause the
video right now give it your full
attention give it your full
concentration
and don't worry about making mistakes
because mistakes are the best part of
learning
you
it's either you
do something well
or you do it wrong and learn from it so
take your time and do the challenge
okay welcome back how did you get around
with that i hope you didn't just stare
at the screen for like five seconds
until the video continued
okay so now we take our magic cube and
what we'll do is we'll duplicate it and
we can duplicate it in two ways we can
either right click on here and do go to
duplicate
which will create another gamecube or we
can simply click on ctrl d and now we
have another cube if we take it here
below
let's make this cube a little bit bigger
and the way we're going to do that is by
scaling it so here we have the scale in
the x direction and we have scaling in
the y direction and in this z but
because it's
2d it won't scale anyways
so let's bring back y to
1
and let's increase
the x scale until it fits between the
two
sides of our game now we have a platform
and let's differentiate a bit between
them so let's make this platform a bit
darker
we can change the color in our spread
sprite renderer here we have the color
and if we click on it we can make it a
bit grayish or blackish
so let's make it
black
and we'll make the square here let's
make it
keep it white or make it a bit gray
let's see
maybe let's just keep it white and let's
change the background oh very fun so we
can go into camera and actually change
the background color which will make
grey
okay seems great enough and let's lower
this magic cube actually let's change
its name to
platform oops
wait
platform and now we have our platform
let's lower this down
and these are the edges of our camera
so now if we
save that
and oh i forgot something good thing i
remember to be click on platform and
don't forget to make this static or else
it will just fall away fall down into
whatever down is click on play
and hopefully yes it holds amazing
i hope you liked the video i hope you
did everything
and
commit everything we done
so committed
added
well actually
made my
magic cube fall
and held it
with a
platform using
rigid body
and colliders a great
so stage all
comment
and i'll see you in the next video
[Music]
welcome back guys to a brand new video
and as advertised in this video when we
click play
our cue becomes magic how's that well if
we press up he jumps if we press left he
goes left if we press right he goes
right and if we go up up up up we can
actually press down down down down down
and make him come back faster to earth
so let's get started
okay so first thing we'll do
is we need a reference to our rigid body
what do i mean by reference to our rigid
body and why do we need it so reference
to a rigid body means that we'll
write up here public
and don't worry about public we'll
explain it later but for now public
means anybody can use it so public
rigid body it's a variable of type rigid
body
and we'll call this my
rigid
body
2d
okay
save that now how are we going to tell
this that it is the rigid body on
my current object
well if we go back into unity
clear those messages pesky warnings and
if we click on cube
right here in the inspector we can see
that now now we have an empty slot for a
rigid body
so if we click on the little circle to
the right we can see that we have the
magic cube or the rigid body of the
platform so let's go ahead and click on
the rigid body on our cue
double click on that
and save it one thing i just noticed is
that if we click on our platform
oh
it's actually we made a mistake we
shouldn't add the rigid body in fact we
should
remove the
cube
so let's remove the cube component from
the platform because we don't need it to
move that's something we should have
done in the previous video but that's no
problem go back to cube and now we add a
rigid body which is magic cube
excellent so save that
now we have a reference to our cube
next thing
we're going to do is we're going to add
velocity to our rigid body so if you
went through the documentation of the
rigid body in unity
in unity documentation
i think you have noticed or maybe you
didn't but there is a
component or how do we call it a
property and my rigid body that we can
use in order to manipulate the velocity
so now
our arrow keys no longer print things to
the console our arrow keys now actually
manipulate the velocity of our rigid
body
so let's do that so in order to access
the velocity we will write my rigid body
to d
which we now have a reference for
dot
velocity
velocity
now if we glance over velocity we see
and actually visual studio tells us that
it's a vector 2
what is a vector 2 well a vector 2 is a
vector into the space so that means
it has the x-coordinates and the
y-coordinates now you should be pretty
familiar with
x and y-coordinates from school it's not
too hard of a math but
it
should be now i i will of course leave
some resources in the
video attached to this video where you
can check out everything about vector
tools don't worry about it
it's pretty simple to create a vector2
we all we need to do is write new
vector2
and open the brackets nothing too fancy
and inside those brackets we can
actually go
through multiple parameters that this
vector 2 can take and it takes a float x
and a float y so
how do we want to move it in our case we
are pressing the up arrow that means we
want the
box to move upwards and not move to any
side to side so how do we do that
we simply
write 0f in the x direction and 10 f
in the
y direction so 10 f means it's a float
because
our parameters told us that the rigid
body takes floats so let's go ahead and
continue the down arrow now even though
down arrow i don't think we'll be
needing it but for practices
practice
practice reasons we are going to add it
and
being this is down instead of 10 f we'll
make this minus 10 f so
save that let's go into unity
and see if
something actually worked so click on
play
our cube falls to the ground and if we
press the up arrow he actually jumps and
then falls down so if you press up up
and then down down he falls faster
excellent job and now you know what time
it is it's time for your challenge
complete the magic so
you have to finish adding velocity using
the left arrow and then you need to
finish adding velocity using the right
arrow so pause the video right now go
ahead and do the challenge welcome back
how did you get on with that i hope
everything went well
it's very easy let's simply copy that
and now when we add it to left
we will have
0 f in the y direction and we will add
it
minus
let's say 10 f let's keep it then
and in the case of the right arrow
we'll add 10 f
in the x directions
direction and zero f in the
y direction
go back into unity click on play and now
if we plus press on the left arrow we
should move left right arrow we move
right up up up down down
everything works perfectly fine
final step as always i don't think i
will keep doing this but for now just to
get you in the habit of doing it so
assets what will should we call this
well
made my cube
move
left
up down and
right
based on the
arrows
with an exclamation mark
so commit that and i'll see you in the
next video
[Music]
welcome back everyone to another video
as the title suggests we are going to be
learning about if conditions and we are
going to learn learn how we can
manipulate them so if we click on play
right here
if our box moves to the left
our console prints that our cube is out
of bounds to the left and if we move to
the right it tells us that our cube is
out of bounds to the right side and the
best part is if we jump it tells us that
our cube is out of mind bound to the
upper side so how are we gonna do this
using if statements so put your
concentration caps on and let's get
started
okay so before we start let's talk about
what if conditions are
why we use them
and their structure so
conditional if statements
they are as the name suggests they are
code that we execute only under certain
conditions
so this is the structure of an if
condition we've used it before in our
arrows and player inputs
so
if
some condition that needs to be true
is true we execute whatever code is
inside these curly brackets
so if we put in a boolean as we've said
a boolean can either be false or it can
be true so if that boolean is true we
execute the code that is inside the
curly brackets
now if this statement happens to not be
true we will simply just avoid or not
even consider the if not even consider
the code inside of the if statement
but if we add another else if and as its
name suggests is if the
upper condition does not
is not true
we check for a second condition which is
some other condition that is true and if
that
statement or condition is true we
execute the code inside of these curly
brackets and if both statements are
false
then we finally use something called
else and this does not have to be any
nothing has to be true in order for this
code to be executed only all other if
conditions above it should be false now
we've used this else our if condition
before we've used it in our code
when we tried to
get the key down from the
player so how does this exactly work
let's zoom in a bit so
input
this input which is a class in unity
uses the function or method get key down
so if you hover over the get key down
you can see that it's a boolean and it
returns true during the frame the user
starts pressing down so whenever our
player presses the up arrow as we've
used as we've said told it here and we
did it using key code which is another
function in unity dot
up arrow
if he presses the the up arrow
it tells the get key down that this
during this frame the up arrow key was
pressed and it returns true that makes
our cue that makes this
code right here execute and moves our
cue and the same is true whenever we
use the other if statements
so now what we are going to do is we are
going to be creating our own if
condition and we are going to do that
in our case for the game so for now if
we click on play
and we move our cube from side to side
whenever he gets out of boundaries he
falls down from our platform and what we
want to do first thing we'll make our
platform just a little bit bigger
so we'll increase its scale
make it just a little bit bigger to give
our cube a place instead of just falling
into whatever down is
and now we're going to check for the
coordinates on its on this cube so this
white frame right here is what our game
actually sees and if we dock our game
view next to our scene view oh and as
you can see it gets smaller to fix that
we can simply go into game and click on
this
uh right here
and simply make it into 16 by nine and
this should always keep our frame at the
same dimensions
so now if we go into our scene let's
make this a little bit wider
and click on our game cube or magic cube
and move it you can see at the top right
in the inspector that the position
changes and this value can actually be
accessed so whenever our cubes goes
outside the boundary so let's say it
should be right about here which is nine
9.42
so whenever it goes outside the boundary
we want to print something to our
console and the same holds true whenever
we go to the other side which is what
should be
9.40 will settle for 9.5
okay so how are we going to do that well
using the structure of if conditions
that we just learned
so let's go ahead save this
and go back into our visual studio and
we'll do this inside of update
so
what are we going to do we want to check
if
the cube has moved outside the right
boundary
so if
what should be right here first thing
we'll need to do is access the transform
of our
cube or game object so it's transform
simply write transfer dot
position
and we're not looking for any position
we are looking specifically for the x
position so it's x
so if transform dot position dot x
is a greater than 9.5 f because remember
it's a float
then inside of the if statement we want
to execute some code and for now we are
simply going to print to our console so
we'll write debug
dot log let's make this a warning just
for fun
so debug dot
log warning
so we should write something inside of
it our
cube
is out of
bounds to the
right side
with two exclamation points to make it a
bit more dramatic so save that
go back into unity
wait for it to compile and understand
what is happening and now clear all of
that click on play
and now if we move to the right side as
you can see our cube is out of bounds to
the right side and the more we move but
if we move to the left nothing happens
so pause that
and now
we'll make a an else if statement
so
else
if
and inside of it
for our else if statement we're going to
check if our cube goes to the other side
of our
screen so it's transform again we access
the position and we need only the x and
now we're going to check if it's smaller
than
minus 9.5 f
and in this case we're going to also
print a warning
which will be our cube is out of bounds
to the
left
side with two exclamation points
so let's make this a little bit neater
ctrl s to save all of that go back into
unity
wait for it to compile clear everything
click on play and now if we go to the
left side with our cube it tells us that
our cube is out of bounds to the left
and on the right side it tells us that
our cube was out of bound to the right
but now if we jump with our cube
nothing happens because it's time for
your challenge and your challenge is to
finish the last if statement so
finish if statement when our player goes
out from the top of our screen
and i'll give you a couple of hints
we'll need to move the cube around in
our scene and understand the top
boundary
and we'll also need to use the if
statement to print to our console so
pause the video right now take your time
with this challenge i'll see you in a
bit
okay welcome back so let's clear this up
and let's see our upper bound so if we
move our cube
we can see on the right here that we
have the y position changing and if we
take the y coordinates and check for
them at about 5.5 our cube leaves the
camera view
okay great so let's go back into our
visual studio and write another else
if
statement and else if our transform that
position and now instead of the x we're
going to be using our
y
so if our transform.position.y
is greater than 5.5
f
we will print another warning
in here and this warning our cube is out
of bounds to the
upper side also the exclamation points
save that go back into unity
and let's wait for it to understand what
we've done click on play
and now if we jump jump jump and we get
out of bounds it tells us that our cube
is out of bounds to the upper side
okay so final step let's move out of
play go back into our source tree
and now we can commit everything so
stage all
click on commit and we'll call this
adding
if
statements
to my game
click on commit
and i'll see you in the next video
[Music]
welcome back everyone to another video
in this video we are not be doing a lot
of coding but we will be restructuring
our code how are we going to do that
well as you see our update method is a
bit different because we extracted all
of the
things that are related so for example
now we have a method that is moving our
cube and it's
right here and we have another method
that is out of bounds in our printer not
only that we've also created a public
method which is printing from outside
which also has a parameter so exciting
and it returns a string and it's used
not inside of cube it's used in platform
a new script that we've created i'm so
excited for this video i hope you are
too so let's not waste any more time and
let's get started
okay so
if we look right now at our start and
update methods we can see that they are
kind of cluttered and there are things
that are not related to each other so
for example we have
all of these if conditions that relate
to our cube movement and we have them
right next to the if conditions we've
created to understand the boundaries of
our queue
so we need to restructure them in a way
and to make it look more appealing to
the eye
so we're going to do that using methods
so what are methods well method
structure are kind of like this just
like we have the start method and the
update method we can also create our own
method and they kind of look like
variables but they are also kind of
different so we have first first of all
is the
access type and this is the
accessibility so we have two access
types it can be either private or it can
be public and we are going to use both
in our project so private is when a
method is only used inside of its class
so for example if you create a public
method inside of cube
only cube can use that method but if you
create a public method
other scripts can use your method also
then we have the return type and for now
we've only used the void which means
that we return nothing we can have a
return type of integer for example where
a
certain method returns an integer it can
also return a string and it can return
other things
we also have a method name so it
the method names should always reflect
what the method actually does
and as a convenience just as we name our
variables the first word will always is
not capitalized when we are naming
methods our first word is always
capitalized and all subsequent words are
also capitalized
and finally we have parameters and we
have a when a parameter has nothing
inside of it that means we pass nothing
and what parameters are they are like
variables that we pass to our method and
we can use them inside of our method
only so
how are we going to use this method
structure well we're going to use it
inside of our
the code right here so
let's begin by restructuring some things
so
as an example i will show you how
much more efficient our code becomes so
let's remove all of these
comments right here and as you can see
that every time we need to comment these
debug logs we need to go there and do
them one by one well we can actually
use all of these
if you highlight them and of course
you're using visual studio and you right
click on them you can see that we have
something up called quick action and
refactoring so if you click on that it
tells you if you want to either extract
it to a local function or extract it to
a method so if we extract it to a method
and by the way the difference between a
function and a method you can actually
use them interchangeably and however you
want but functions are usually
methods that are inside of a
another method but a
method is a method that is outside
the method we're currently doing so it's
a bit confusing you can use both of them
interchangeably don't worry about it so
what are we going to name this
method here
and we are going to call it
printing
to
our printing wait to
our
console
and click on
enter and now we have this function or
method right here and as you can see
it's a private method that doesn't
return anything because it's void
and now if we want to comment that out
we can simply comment this function out
and all of it is commented out and it
won't be printing to our console so this
is the first benefit of using
uh methods so let's go ahead and
put this under update so if we click on
ctrl x to cut it
and we'll put it below update
i like to put update right below the
start method to have a nice and cohesive
structure to our code
next thing we're going to do is we're
going to extract
two another methods so first of all
we're going to highlight all of the
if conditions in our up for our
for moving our cube so highlight all of
them right click create a
extract a method we'll call this method
moving
our
cube
and we'll also extract this method and
we'll right-click
go to extract method and we'll call this
method what should we call this
out
of
bounds
printer
okay
so now oh sorry for that
get back to zoom in a bit so now as you
can see our update method is very
cohesive and it
we can easily see what our update method
does so it is moving our cube and it out
of bounds printer it checks for out of
bounds whenever our cube is out of
bounds it prints something to our
console so now you can see that we have
this
method right here and another one
right here and finally we have the
printing to our console excellent
now we are going to create a second
script and create a public method just
to demonstrate how everything is working
so
first thing we'll do is we'll create a
public method just under update and
we'll call this
well first of all let's make a public
we'll make this a void
because we don't want it returning
anything for now
public void
no we'll use it
we'll call this printing
from
outside
okay
you don't have to make your
method names that long but just for the
sake of giving an example so
what this function will do it will
simply
something
or a certain message that will have
hello
from the
other side i don't know why from is
capitalized it doesn't have to be so
it's hello from the other side
let's go back into unity
click on platform because it's the only
other object that we have besides the
camera let's add a component and let's
create a
platform
plot
form script so new script platform
excellent let's go ahead and create it
and it in a bit it should be added and
now if we
now we have it in our project so double
click on it and it should open in
our visual studio as you can see we
already have the void update method and
the void start method
now inside of start
we are going to get a reference to our
cube script and use the public method
that it has
and how are we going to do that well
we're going to do that using something
called
find
object of type
and object of type
has these two
operators right here that
we need inside of it to tell which
script we are going to use so it finds
the object of type
cube
and visual studio always helpful and now
if we click on dot
we can see that we can use anything that
is inside of the cube
so if we for example want to access the
start method we can't
but if we want to print as you can see
it gives us the printing from outside
method
because it is public so if we save that
and go back into youtube unity
and let's also save our scene and click
on play and before we do that let's
clear this up and as soon as we click on
play
hello from the other side
how cool is that so we've created a
function or a method that is inside of
the cube
but we are using it inside of the
platform
that is so cool and this actually is the
basis and it's very crucial because
we're going to be using it a lot in our
game in the next sections
so
your challenge
is to create your own method
you will create a simple method with a
string return type so instead of void
you will have it as a string type
you will also give it an integer
parameter
and you will use it with the string and
return it
so it's a bit of a big challenge but i
think you are ready for it
and a small hint use
to string
and it will require a bit of research to
understand and do the challenge take
your time don't don't be afraid of
making mistakes as i've told you
trying and failing is not the end of the
world so i'll see you in a bit
okay welcome back so
now we are going to
change our
uh
method just a little bit so instead of
void we'll make this a string
and it currently doesn't take any
parameter so we'll give it a parameter
which is an integer
and we'll simply name this integer value
to not be over complicated but as you
can see right here
we have a squiggly red line that means
that our function is not working
probably properly
why is that because
it has a return type which is a string
but it's actually not returning anything
so how do we fix that
well we need to write here return and we
need to return a certain value
and what that value is well it needs to
be a string so let's go ahead and create
a variable inside of our printing from
outside
so this variable will be a string we'll
call this
variable
printing
something
and what will have it print well
the
value
we
were
sent
is
and now we can use this parameter that
we've been sent from the other side
and now in return we will
return print something and that should
fix
our squiggly red line
problem
but because we've given it a parameter
in here
where we call it from should also give
it a certain parameter so we can we have
to give it an integer and that integer
let's say
will be 8 or 4 or anything or you can
even create
a variable right here we'll call it an
integer we'll call this
value to
send and it will be equal to let's say 9
and in here we'll
send the value to send
save that this actually returns a string
so let's put it inside of a string
reference which we'll call
string from
out
outside
equals
and now we'll simply
debug dot log
and we'll be printing the string from
outside
so close that
save that
go back into unity
so clear everything click on play
and now the value we were sent is nine
excellent job
and one thing i want to make clear is
that because this is a string and this
method returns a string we can actually
directly put it inside of our lock
excellent job everyone i hope the
challenge wasn't too hard i thought it
was a little bit step up and it needs a
little bit of research but
i hope you tried your best and as always
before we go
we need to stage all
comment
created my first
public
method with
return
type
commit that and i'll see you in the next
video
[Music]
welcome back everyone to a new and very
exciting video in this one we are going
to learn about prefabs not only that we
will learn about prefabs how we can use
them from scene to scene here you can
see that we have a diamond with
something called a polygon collider we
also have this magic cube and a small
circle but actually the circle moves
with our cube because it is a child of
that cube
we can also we've also created a second
level level one and level two here we
have three cubes as you can see and for
some reason they are blue and we'll see
why they are blue we also have a diamond
right here and if we click on play all
of them fall down and
that's it so it's so exciting
i'll see you in a bit
okay so what is a prefab
well basically it's a template for a
certain game object so
if we
created a game object with all its
components and its script and its
position
we can create a template from it
to create other similar game objects
prefab system allows you to store a game
object with all its properties so let's
say our prefab has a collider it has a
rigid body and it has a script whenever
you create a prefab from said game
object you will have the same properties
in it
so why do we use it for well we can
reuse a game object configured in a
particular way
we can edit many objects at once
and we can use the same object in
different different scenes much easier
so let's go ahead and demonstrate these
three uses
so
creating a prefab is actually very very
very simple you all you need to do is
simply click on the thing that you want
to prefab so for example we want to
prefab our magic cube
click on it and drag it
into our project and now we have a
prefab of our cube and you know it's a
prefab by looking up at the hierarchy
and you can distinguish it by because
it's a bit more blue
excellent so now what can we do with our
prefab
if we click on it you can see that it
has the same properties
as
the cube in our scene
and now if we click on the prefab and
drag it into our scene you can see that
we can create three
beautiful magic cubes extremely easily
and this is very helpful in many ways
so let's demonstrate how prefabs work so
let's say we
click on this magic cube which we see in
the hierarchy is number one
so let's say we want to change its color
so if we go into our sprite renderer and
choose color and let's make it red so
now we have a red magic cube
we save that and you see that the other
two magic cubes are still white and by
the way these cubes are called instant
instances of prefab
and if you look closely here in our
inspector you can see that we have
another tab open
so we have the open which opens our
prefab which is the magic cube we can
select
the prefab and we can overwrite and what
this does it applies whatever changes
that we've made to our current instance
to our prefab so the things that have
changed you can see that they are also
highlighted in a
blue color right here and we changed the
color so if we click on override and
click on apply all
what should happen
is that all of the other instances of
that cube change to red and down here in
our project you can see that our magic
cube is red now
that is
very cool and you can start to see how
helpful that is
so let's say we change back
change back the instance to white
let's take another cube and change that
to
green
so now
if we apply this to
our prefab what do you think should
happen will all of them turn green or
will only the one that is the red turn
to green
let's try that apply and oops as you can
see that only the prefab that was
originally or the instance of prefab
that was still the same as the original
is changed to green but the ones that
we've also modified don't change back so
private prefabs are a bit tricky but
they are very helpful
so for example let's go ahead and delete
those three cubes
let's go into scenes and let's simply
duplicate our current scene by that we
create a second scene let's rename this
to
level
two
and our original scene will be level one
so now yes it asks you for a reload
simply click on yes so now in level one
we have these three cubes and in level
two apparently we also have these three
cubes so let's go ahead and delete them
save that so in level one we have the
cubes in level two
we don't have cubes
so what are we going to do about it well
instead of going to level one
and duplicating or copying the cubes we
can simply go to our project and we have
a magic cube and we can
add it
easy as pi
right into our scene and now we have a
cube a magic cube in our scene
okay great so that's a prefab now what
are children well
let's go ahead and create go to assets
and the create
a sprite and the sprite will be a circle
so now we have this
let's say
magic
child circle
okay so magic child circle we can go
ahead and add this magic child circle to
our scene and by the way this magic cube
is the prefab this is just the sprite
by the way we can also organize all of
this so if we create a folder called
this sprites
we can put both of these into sprites we
can also go ahead and create another
folder called this
scripts
and now we have these scripts inside of
the folder scripts and if we add another
prefab we can also create a folder for
the prefabs
so now we have this magic child circle
why do we call it the child circle well
because we are going to child it to our
magic cube and we do that if by simply
taking our
magic child circle and dragging it right
under our magic cube and now it's a
child
now what does child mean if we click on
the circle we can move it as we always
do but if we click on the magic cube
and we move it you can see that the
circle moves with it that means it is a
child and if we scale our cube
our circle also scales
and if we scale in the y direction it
also scales if we rotate
so let's see if we rotate it
the circle also rotates and these are
properties of a child
it grows with its parent
and the parent is magic cube so it grows
with its parent it shrinks with its
parent it moves and behaves just as its
parent does and this is very helpful
because sometimes we may need to add
children so if we have
a
an object that has several objects
inside of it and we want them all to
move in unison instead of coating all of
the children we can simply code things
to the parent and the children will move
with the
parents so
we'll be using a lot of
uh parent children relationship will be
using prefab also a lot and now it is
time for your challenge and your
challenge is to create a new prefab so
create a new object in our scene
whichever scene you want
prefab it
make an instance of it in a different
scene
and add a component to that instance
apply the changes to prefab and see what
happens and if you want as an extra
challenge you can also make a child
parent
relationship somewhere in our scenes so
pause the video right now and go do the
challenge
okay welcome back how did you get on
with that i hope it wasn't too hard so
let's take this cube put it over here
our magic cube which is a square
ironically
and now let's go and go ahead and create
something so we'll go into sprites let's
see we'll create a
diamond because diamonds are forever so
diamond
click on enter and let's go ahead and
put it in our scene
and we'll
put it inside of sprites so now we have
a diamond let's make this diamond a bit
bigger and let's change its color
so let's make it a blue because diamonds
are kind of blue i guess
so now we have this diamond in here
and what we want to do is we want to
so what was our challenge it was make an
instance in a different scene
and add a component to the instance okay
so we take this diamond and let's prefab
it and now because we have two prefabs
let's create a folder
call this prefabs and everything is
organized and neat
so now we have the diamond let's go
ahead
save that
go back into our level one scene and we
have three cubes here but no diamond but
we can easily add one from our hierarchy
super easily
so let's add a components component
let's add a rigidbody
2d
and let's also add a
collider and what kind of collider
should we add to it
let's go ahead and add a
circle yeah sure why not a circle well
actually it should be a polygon collider
let's make it a polygon collider and it
fits perfectly
and actually just for the fun of it
let's go ahead and rotate it in the y
direction
nope not in the y direction i meant in
the z direction
okay great so save that
but right now we are clicked as you can
see we have we are clicked on the
diamond in our scene and we've actually
added a rigid body and a polygon
collider so
it's not added to our prefab if we click
back on our prefab in projects here
below
we can see that it doesn't have any
rigid body or
collider so back into diamonds
click on override apply and now in our
second level save that in our level two
wait sorry for that
scenes level two the diamond
actually has rigid body and a polygon
collider which is great so click on play
just to see it fall
our diamond falls
and everything falls and as you can see
the
even even
the circle falls with our cube but
because it doesn't have a collider nor
does it does it have a rigid body but it
moves with our cue so
i hope you did the challenge i hope you
enjoyed this video and i think this will
be the last video in our section in the
next section we are going to actually
start creating our game so exciting so
review this
make sure you understand everything in
this section and don't forget to
always commit our work so
let's commit this
stage all
added a diamond
prefab and
added
a child circle
to my
magic cube
okay great so commit that
it's saved we have it in our
comments right here and i'll see you in
the next video
hey
you are almost 50
the way with the course how cool is that
you know that you are one of the fair
few i
think
less than
20
make it 50
of the way down the course so
congratulations i hope you're having fun
i hope you're enjoying your time let's
not waste any more time and let's get
started
[Music]
and welcome back my favorite game
developers in this video i'm going to
talk a bit about
game design and as you can see i've
already started and already the google
slides are very excited to tell tell you
about the game sketch so
the game sketch is the following
now
it's not very impressive but it will get
the concept of our game around so you've
already watched the introduction video
where i've showed you the game that we
have finished already but now i will
take you through the steps that it took
for me to get the game
developed so first thing first i've
created this mini sketch and as you can
see
well it's not very impressive but it
gets the job done so first thing first
we have the tiles right here which will
define our world
and we have the background tiles or the
world confiners right here on both sides
next thing we have are the doors so
we'll have the enter door through which
our conqueror right here this little guy
can enter through and start the level
and this is the door right here that he
has to go through in order to advance to
the next level or room
next thing we have the bombs right here
that
i've sketched as burning
and they will explode as soon as we get
near them well not as soon as they will
start burning when we get near them and
they will explode eventually
we have the hearts that we can pick up
in order to increase the lives we have
we have of course the hanging sheets
right here that we can climb to get to
platforms that are unreachable
we have the diamonds of course that we
pick up to increase our score and we
have the little monsters right here that
will try to attack us and kill us but we
have the power of thor's hammer that
will crush any enemy in our path
and also we have this little square
right here and if you've noticed in the
introduction of course you've noticed
because i've told you like 10 times
become because i'm so proud of it this
is
the camera that will follow our player
wherever he goes so instead of having a
huge camera around the entire level and
having to move our tiny tiny player
around we make the camera follow our
player wherever he goes
that is very cool and i encourage you to
create your own game sketch and see how
you want to make your own game
so next thing let's talk about the 2d
platformers because our game is going to
be a 2d platformers
so i'm sure you're familiar with a
couple of these this is a recent game
called celeste which
many regard as one of the best games of
i think 2000 2017 i'm not sure but it's
a fairly modern game and as you can see
it's just like our game where it has
styles and it has a
pixelated character that moves around in
the
2d platform that they have created
next thing we have a hollow knight not
sure if you've played this game but it's
really amazing it's
similar to dark souls and it's
difficulty but it's a 2d platformer and
i've used modern uh examples just to
show you how much 2d platformers are
still
relevant in game development and you can
see right here that it also has a tile
maps and platforms and backgrounds and
little pixelated
although they are better more polished
than our game and not as pixelated but
the same concept applies
and finally we have shovel knight i'm
not sure if you've played shovel knight
but it is an amazing game i've played it
i finished it it's very cool and as you
can see this is very similar to our game
it has the ladders it has the enemies
while the enemies are bigger and it's
pixelated just like our game and the
final example i found this on google i'm
not sure who did it but as you can see
they have
sketched up the game and the pixelated
it and it shows the tiles that were used
to create the game we will use similar
tiles or similar
way of
tiling our game and making our game
a 2d platform just like this one with
ladders with platforms and with a
background
so castle conquest game design what am i
going to talk about right here so this
is a screenshot of our game and let's
talk about the core mechanics so we'll
have our conqueror running jumping
climbing and he will also be attacking
what else should we talk about
the core gameplay well it's going to be
getting from the start of the level from
the starting door to the end without
getting hit more than three times as you
can see uh as you saw in the
introduction video i've showed you that
our player
uh or the conqueror is the player in our
game has only three lives and uh that's
uh not talking about the lives that he
can actually pick up but every time he
gets hit he loses a life and if you lose
three lives you're done you need to go
back to the main menu
so let's talk about game story also
because that is you might think that
well you know what i don't think we need
the game story and you are completely
wrong because the game story is
well the game story will be the
i'm not going to say the core but it is
the nucleus around which the core is
built
so what is our game story well you are a
king and you've just inherited the
castle from your father monsters pigs
have taken it and you need to defeat
them all and you need to go through
every room and try to crush every single
one of them and also along the way
you'll need to collect the diamonds so
this will make the game much more
interesting and as you're playing
through it you can feel that you have
the
ability to take charge of whatever is
happening in the game and you have a
reason for killing the little pigs not
just for the sake of killing them you
have a reason and you're collecting
diamonds for a reason because your
castle is infested with them and you
need to take back your pride
okay that's a bit dramatic but you get
the point you always need a story for
your game next thing we're going to talk
about are the technical requirements to
create this game so
as you can see we had a lot of stuff so
first thing we need is a tile set for
the background and the foreground with
some elements so
i've chosen a tile set that i will show
you later on where i got it from
and i will leave it of course in the
resources
feel free to go and get your own tile
sets but make sure that you have a
foreground and a background tileset for
our game
next thing we're going to use inputs
from the keyboard to control our game
we will add a follow cam that will
follow the player or the conqueror
wherever he goes and zoom in and out
depending on his movement as you saw in
the introduction video when we're
running there is a certain zoom in when
we're standing still or idling there is
a certain
zoom out and so on and so forth and will
also create an automatic way of adding
background to our game that means that
we'll add a rule will add rules to our
tiling and make all the background
automatically fill everything and save
us a lot of time
so
let's talk about some more gameplay
features that we'll have
as you can see right here our
little player is punching the air but
even though the pig is a bit far away
but the conquerors movement we've
covered this before but it's going to be
running jumping and swinging the hammer
as you can see right here depicted in
our screenshot
there will be hazards there will be
bombs that will that
bombs that burn and explode if we're
near and they can actually kill us
we will have a start and end point we'll
have doors
that the conqueror walks through to get
from one room to the next and by room i
mean the levels of our king
next thing we'll have the pickups and
the pickups are lives along the way for
the player to pick up as we walk and all
the diamonds that you can carry with you
now it's time for your challenge and
your challenge is going to be to create
your own
game design
so
figure out a story for our game think of
a compelling story a story that will
make but whoever is sitting behind the
computer and who's going to play your
game feel excited and give him reason
give him reason give him
the motivation to go up and kill all the
pigs and collect all the diamonds next
thing you need to find find out the game
mechanics you want maybe you want to add
other game mechanics and i completely
encourage you even if you don't know how
to actually implement those mechanics
just write them down keep them with you
and along the way you will find out how
to create them
you will go and download your own
sprites and tile set
and as i've told you make sure that you
have the foreground and the background i
will leave the links in the resources
for you to go ahead and download or
search for whatever tile sets and
sprites you want or you can simply use
the same that i'm using
figure out what features you want to add
so as i've told you we have picking up
things we have climbing the sheets you
can also add your own features i'm not
sure what that those will be but for
example you can add power ups that's a
good idea so write that down also and
figure that out for yourself and
as i've told you this is going to be
very exciting i'm so pumped to start
creating this this game and i hope so
are you so let's start our journey
together and i'll see you in the next
video
[Music]
welcome back everyone now we are
starting a new
project which is very very very exciting
okay so first thing we are going to
create our project so open up your unity
hub and go into add new so it will be a
2d project and we'll name this
castle
conquest
to
d and remember where we're saving it
because we'll need it for the
repo to create
and now we wait for the project to be
created i'll see you in a bit
welcome back so
i've accelerated the process of creating
the unity project using the magic of
editing
and now we will go we are going to set
up a new repo so this is from magic cube
to set up a new repo simply click on the
plus button up there you can close this
tab
and click on the create button right
here so we browse for our path
so wherever you've saved your path go
into that and click on the castle
conquest 2d
select the folder keep it on good keep
the create repository on account
unchecked for now
click on create
click on yes and now we have a repo so
as always
we know that we should simply
click on the library ignore everything
ignore everything beneath library
click on ok
now we go into the get ignore double
click
open in our notepad
and you should have everything
by copying it and pasting if you don't
remember how we did it check out the
i don't not sure which video i think
it's the second video in the previous
section and you'll find where you can
get the git ignore
or simply google it and now we have
everything set up so we simply going to
stage all
commit
and call this
initial
commit
click on commit and we are ready to go
so
first thing we're going to do is we're
going to be importing the sprites i've
provided you in the resources so go
ahead and get them
simply click on them and drag them into
our
project right here now before we get
started i want to take a moment and
explain what
is a sprite so
this is a sprite this will be a our hero
or our conqueror
and as you can see he is a image so a
sprite is a 2d object and this 2d object
has a graphical image
on it called texture so sprites are 2d
objects and they have graphical images
on them called textures
and they are used by adding a component
called sprite renderer to an empty game
object so we create a game object we add
a sprite to it and we can
have a graphical image
on it
okay
so
now that we've explained what a sprite
is
it's
time for us to create our terrain so
our or before even that it's time for us
to slice up our terrain so right now
if you click on this small arrow right
here you can see that it's a single
image
so what we need to do is we need to
slice it up so if we click on it you can
see here in the inspector that we have
many options and one of them is the
sprite mode first thing you need to make
sure that your texture type is of sprite
2d and ui and the sprite mode should be
multiple
so
click on that
and apply everything and go into sprite
editor so as you can see here we have
all of these
so the top ones will be our foreground
and the bottom ones will be our
background
so here on the top on at the left you
can see that we have multiple ways of
slicing our sprites one of them is
automatic so let's try that as an
experiment so if we click on slice
we can see that it slices them up pretty
good but that is not what we need we
don't want this entire block to be a
single slice we want to slice it up into
four little sprites and this one also i
think this more than i think this one is
nine surprise this one is for little
sprites so how can we do that well
actually in slice we have something
that's called grit by cell size or grid
by cell count we'll be using the grid by
cell size
and i know that it should the pixel size
should be 32
by 32
so we slice that up click on slice and
now we have our sprite sheet sliced up
into little sprites
okay great and you can click on each one
of them and check the information about
it so this is terrain
this is terrain also and each of them
has a number now if you have the time
and you want to be very meticulous with
this process you can actually rename
each one of them and make it your own
but we don't need that honestly
okay great so apply that in on this
button right here apply that
and now we
have our sheets sliced up
excellent
great
and this is everything we'll need to do
and it's time for a challenge and your
challenge is going to simply be slice up
your own sprite sheet so import whatever
sprite you choose to use for your game
i've given you the resources the website
where you can find
free
game arts
and
simply import them slice them up
into sprite sheets for the background
and the foreground tiles make sure that
you have background and foreground
and
as a last
step of this process we are simply going
to create a folder
we'll call this sprites
and we'll drag the terrain inside of it
and another thing maybe we'll change
this and name this
level
zero because we don't have any other
level simply level
zero okay so this project will be great
it will have lots of sprites it will
have lots of scripts so let's start with
some good organization habit for the
first
video and i'll see you in the next one
[Music]
welcome back everyone to another amazing
video and this especially is the best
video i think in the whole course
because we are actually creating our
platform as you can see here we've made
a small platform we have the style map
over here on the right we have on the
left also a tile map grid in our
hierarchy we've used all the sprites
that we've sliced before to create this
platform right here so let's not waste
any time i'm so excited for this video i
hope you are too so i want you to summon
all your creative power to this video
and i'll see you in a bit
okay so tile maps what are we going to
do
well first thing we did is we got our
sprite sheets
we sliced them up into little sprite
sheets
we are going next to create tile assets
we are going to take those style assets
and add them into our tile palette and
finally we'll use our tile palettes to
create our tile
map
okay great so back to unity
where we are going to
first of all go to window and look for
our tile palette which should be under
2d
and style palette so click on that and
now we have our tile palette feel free
to dock it wherever you want i feel like
i want to dock next to the inspector
make this a little bit bigger because we
are going to need it needed later on
next step we go into our hierarchy here
on the left where we don't have anything
except for main camera so right click
and go to 2d object and look for tile
map when you click on it we can see that
a grid has been created it's called the
grid in our hierarchy and a tile map so
let's change the name of the style map
to
let's go into inspector make sure you go
from inspector to tile map so tile map
changes to
background
and
create another one
so in grid we're going to create another
tile map and we'll call this one
foreground okay great and we'll also
rename this from grid to
tile
map grid
everything is great so
now what we're going to do
is we're going to
create a new tile palette
so go into tile palette and here under
create new tile palette click on it
and it will ask you for a name
we'll simply name this
main
wait main palette
create
and it will ask you where you want to
save it it's
these are your assets folders so let's
go ahead and create a new folder called
the styles
and save it inside of our tiles select
the folder now we have a new folder
which styles and it has a main tile
palette and this is our tile palette so
what are we going to do now
go back into our sprites in the
hierarchy on the left
and choose all of these sprites so
go ahead and choose all of them to do
that more fast click on the first one go
to the last one hold shift and click on
it so you choose everything
and drag them into our tile palette and
we should have a big huge mess right now
go back to tiles
and inside of tiles select the folder
and save them there so
wait for them to become tile assets
and they should be
now
okay so as you can see a huge mess has
been made now of course we are going to
be moving all of these and rearranging
them now you can rearrange them the way
you want to
i will do it later on
i will it will be the same arrangement
as the one on
the terrain feel free to do your own
arrangement so
now it's time for the exciting part so
let's choose one of these styles and
start drawing
but as you can see
these are very small so what's the
problem the problem is that when we are
choosing our sprites they are actually
the pixels per unit is 100 so how are we
going to make them fit
we're going to change this to 32. so go
to our sprite click on it go to the
inspector and make sure that the pixel
per unit is 32
apply that and they fit perfectly into
our squares
great
back to our tile palette and now
let's go ahead and draw a simple very
very simple
background so we can also let's learn a
bit about the stuff up here so every
time you want to draw you have to make
sure on which active tile map you are so
for example i just drew a ti a bit of
tires which were on the background which
was not correct you need to make sure
you choose the right active tile map
and
over that you can see that we have this
brush with which allows us to draw a
single
tile every time
we have next to it this
box drawing which we can simply click on
here and drag it and make as many boxes
as we'd like we have this
pick where we choose one of this these
and we can actually change all of them
and
now you can also experiment with all of
this and we finally have this
uh what is what is this a an eraser
which where we can remove whatever we
feel like removing
so let's draw this again
and now we are going to change into
foreground
and now when we are foreground we choose
the tiles for the foreground
back to
background make sure that we
everything is in the background and the
things in foreground are always the
tiles for foreground so now if we click
on play
this will be our game view how cool is
that we're beginning to create our game
excellent
but
something i want to point out is that
we need to make sure that we are working
on the right layers so what do i mean by
that well
if we go back into scene and our tile
palettes if we click on the background
we can actually draw over our foreground
palette tiles which is not very good we
need to make sure that whenever we draw
our foreground is well in the foreground
so how do we do that we do that using
sorting layers and sorting layers are
very very cool aspect so if you go into
the hierarchy in background you can see
that we have a tile map
under it we have a tile map renderer now
if you want to go into the unit
documentation and find out everything
about everything
feel free to do that but what we're
going to focus on are these additional
settings so if you have it closed open
it up
and you can see that we have sorting
layers and we have order layers
and now on foreground you can see that
we have these sorting layer and order
layer
so we need to create a sorting layer for
our background so click on the sorting
layer which is now default and click on
add sorting layer
so to add a sorting layer simply click
on this plus right here
and we'll call this our
for
ground
let's add another sorting layer and make
this one
back
ground
now we have two sorting layers and below
it and above it we can see the tags
which is something that's useful for
coding and
layers below it which is good for
collisions we'll talk about these later
on so go back into foreground
and now in the sorting layer instead of
default choose foreground
and for the background choose
background but as you can see here our
background still is in front of our
foreground why is that well if we go
back into
the layers to the sorting layers the
ones below will be rendered first
so if we move up the background and put
it above the foreground the foreground
will be rendered in front of
the background and every time you need
to make sure that you have your layers
in the right
ascension or the sanction
okay
excellent save that and now we are going
to create a simple
platform
a very simple platform but first no not
challenge not yet first i will use the
magic of editing to
rearrange all of these styles in here
and it's not going to be something very
amazing you can do it the way you wish
to do it i'll simply make it the same as
our original arrangement okay i'm back
from my magical editing trip
so as you can see i've rearranged all of
my tiles and i forgot to do something i
forgot to teach you how to actually do
that so excuse me to do that simply
click here on edit when you click it you
actually have access to all of these
tiles so
if you check on here you can actually
select an area of the grid using s and
then you can move it using m so click on
s click on one of the tiles
click on m and now you can move it
wherever you want and when you finish
editing simply click on this edit button
and it will save for you so let's change
this back s
and m and save and ctrl s to save
everything
and now
it's time for your
challenge and your challenge is going to
be to be to create your own platform so
create the foreground and background
tiles
create a new tile palette
rearrange the tiles in that palette just
as i did or find your own personal way
of rearranging them
create a platform from the foreground
with a background so
pause the video right now rearrange the
tiles the way you want them to be
rearranged and then
go ahead and create some kind of
platform don't worry about how much the
platform should be amazing or great this
is just for simple training i'll do it
later on but pause the video right now
and try your best okay how did you get
on with that i am so excited to see what
your palette would look like
so now i am going to create a small tile
just inside of our screen so if we dock
the game right next to it and it's 16.9
great so we can see it but for now let's
simply keep it there
and i'm going to create a platform just
inside this camera and to not bore you
with all the details i'm going to
again use the magic of editing it's such
a good magic
it's better than harry potter's magic
and i'm going to
create a
grid or map right here so i'll see you
in a bit
hello and welcome back so as you can see
i've created
a small platform right here and what
this platform consists of is
just
i made a small or not small a rather big
wall in here an obstacle
maybe i'll make it smaller later on i
made a little platform here where we
might we might put i don't know maybe
diamonds or a hidden box then i made
these kind of steps where our player can
jump on and that's basically it nothing
too fancy
and i hope you did create your own
platform or you might have waited for me
to create the platform and then took
inspiration from it
but what i want you to do is create your
own platform don't just copy mine
because this is the best part in the
course it's actually creating levels
using the amazing magic of
tile maps a lot of magic in this video
and i'll see you in the next one
[Music]
welcome back everyone to a brand new
video and this video we are going to be
investing time
yes we'll be investing time right now to
save ourselves a lot of time later and
we'll do that by creating rules for our
tiles so as you can see and now we can
sim
automatically
create tiles so as you can see they fill
up automatically which is very cool and
very helpful
so
i'll be teaching you how to create these
rules i'll give you all the resources
needed it will take some time and some
understand some understanding to get it
but don't worry about it everything will
be explained so
i'll see you in a bit
okay so first thing we're going to do is
we're going to be importing our 2d
extras tile map rules
there are two ways to go about this you
can either go into a google and type 2d
extras unity and then go into your into
the first
result which is github and download
download it from here
you'll get a zip folder and you simply
have to import it
first of all extract it and then you
simply drag it into your
unity assets or you can use the one i've
provided you in the resources i will use
that right now so simply take this rule
tile that i've provided drag it into
unity and put it inside of assets
wait for it to import it will give you a
long list of things to import simply
click on import right here on the bottom
right corner
wait for it to finish up and now
you should have this folder right here
when you do get this folder you can go
into tiles
and you can simply
let's go ahead and
put all of these in a
single folder let's go ahead and call
this
terrain terrain
tiles
go ahead choose all of these
and simply drag them into terrain tiles
to have
more space and now if you right click
on your
whatever you where you want i recommend
you go into tiles go into create and you
can find at the top right here that you
have something new one one is a prefab
brush and the other is rule title so
click on rule time
and and for this particular rule set we
are going to
make rules for our background so let's
go ahead and call this
background
rule
tiling
and now if we click on it and go into
the inspector you can see here that we
have
some weird structure of
windows so
we have the default sprite and we have
the tile rules a list which is empty and
we can add this list by clicking this
plus button right here and we can add
rules
first thing you need to do
is dock this inspector so simply go up
to the upper right of your screen and
click on this little lock here and now
this will not change this will be very
helpful
so now as you can see it tells us that
there are none
sprite
so we need to add a default sprite and
because we are working on the background
we'll be only working on the background
sprites
so go ahead and add whatever random
sprite you want to be the default and
now we are going to start and
by creating our tiling rules so the
first rule will be for a tile
which should be in the middle just like
this one which doesn't doesn't have any
sides to it or neither does it have any
little
i'm not sure what those are what those
are called these are for the corners by
the way and this will become all clear
just in a bit
so now we've created our first rule
congratulations
let's go ahead and add it to our tile
palette so you can either create a new
tile palette simply
just for our rules or you can add it
right here up there
above all the default tiles i'll add it
into this one
because it's more practical i believe so
simply click on this background and drag
it into our tile palette and should it
should show right here so now if we
click on this one
we can actually draw
these rule
tiles see that okay great and as you can
see the all of them are of the same type
but if we choose to
create rules for it so for example if we
click on this one as you can see
everything changes
why is that well let me explain these
how these rules actually work so
let's see this three by three box right
here and if we add we can actually add
these kind of arrows and as you can see
the more we add the more it changes and
what these mean is the green arrow means
that there is a tile above it so when
there is style above it to the left of
it to the right of it and below it then
we can draw this tile so this is a rule
and if we click on this green arrow
again
we can see that it becomes an
a red x and what this red x means that
it will only draw when there is nothing
to its right and we can see here
oh and if we actually click here it
actually
makes
well it shows us what will happen if we
add a tile here
and you might be wondering why are all
the other tiles this way well because
it's our default sprite so let's go
ahead and add another
rule and let's keep this like this
because
actually this is our rule for this
particular tile so let's go ahead and
add another rule and for this rule let's
go back into sprites
we'll add a
corner on the right side so let's go
ahead so what do you think the right
side should have as its rules well i
think it should have
one below it one to its right and one on
its diagonal and it shouldn't have
anything
on either side
now nothing changed pretty much but
that's okay because we'll add another
rule
and for this rule let's see what we have
let's add this one
oh
and in this case if we have something to
on these sides and nothing on that side
we should have
this
right here and it's
pretty much correct now
so let's go ahead create another rule
and add this one to it
so now if we have for example what
should this have if it doesn't have
anything to its right
and it has something on its left it
should create this one
another thing about these rules right
here is that you can actually change
them and they can be either rotated or
mirrored on the x or y axis
what does that mean well if we click on
this one you can see that
it rotates all the rules so it
if we don't want to create rules
for for example we want to make a rule
that's like this one
okay we can simply click on the mirror
mirrored on the
uh
axis and it will create that rule for us
but we won't be needing that because our
assets are rich and they have everything
in them
so
now
i'm going to create
a set of rules let's simply delete that
one because we don't need it i'm going
to create a set of rules and before i do
that i'm going to issue you a challenge
and your challenge is going to set up
your own rules
because
maybe i believe even that you can create
better rules than me for the background
so first thing is import it to the
extras file i've provided in the
resources
then you have to set up your rules for
automatic tiling
and use the rules to paint your own
platform so
go ahead and try your best and if you
feel that you can't even come up with
these simplest rules
i have provided in the resources also
the rules i've screenshotted everything
beforehand so
i'll see you in a bit
okay
welcome back so how did you get on with
that i hope you at least tried to create
some rules
so let's show you let me show you what
i've done
so i have created i think it's about 17
rules
and the way i did them i actually
started looking at different ways that
each style might work and how it should
be positioned
and of course if you don't have any idea
how to create the rules i've provided
you some pictures and or screenshots
that i've made so you can
copy them and use my tiles but remember
mine are not perfect by any means and i
left out a lot of tiles because it's a
very exhaustive list i want to create an
example for you to create your own rules
it will not be easy it will not be done
in
10 minutes i think this actually took me
i think about two maybe two and a half
hours to finish all of them and test
them and make sure all of them work so
to demonstrate how the automatic tiling
works let's go ahead and choose to erase
a couple of them so as you can see when
we erase them
new tiles are created to wrap around and
as you can see we have a mistake right
here
and there there might be a lot of other
mistakes but some of them work like this
one for example works perfectly fine so
let's go ahead and delete all of these
and delete all of these
and let's try them out in our platform
and see how they work so let's go ahead
and click on this choose the automatic
tiles
and let's remember to always have it on
background so let's create
something right here and then we'll
create something right here and as you
can see they fill up automatically
and it's
perfect i guess let's see if
oh there is something right here i think
we need to create another rule for that
i believe it's the one where you have
only two on each side so
let's see
okay so let's go ahead and create a new
rule and let's see which one we should
use so we want to cover
we want to cover this area right here at
the top and one over here so we'll
choose which one which one okay this one
so let's drag it in here as you can see
it fills up automatically but that's not
what we want we want to actually create
a rule for it to always follow because
that will always default to this one
so it doesn't have a tile to its upper
left it doesn't have a tile to its
bottom right
and it has
tiles to
both sides and files to
above it and below it and on either side
excellent so now you can see that we
have our rule set up right here we can
automatically tile all the background it
makes our
platform much more aesthetic than having
all of them the same you can create also
a rule for your foreground tiles i tried
it it's meticulous it takes time
and i encourage you to try and create
that also it will make your life 20
times easier
i hope you enjoyed the video i hope
you're excited as i am about this in the
next video i think we'll be
finally adding our player or our
conqueror as we've called us will be
calling him our conqueror
so i'll see you in the next video
[Music]
welcome back my fellow game developers
as you can see we've created finally
we've created a
player and this player is our conqueror
we'll call him jimmy so
jimmy right now doesn't do anything but
if we click on play we can see that our
jimmy conqueror actually has an idling
animation that's running right here
below i'll
teach you everything that we've done
you'll have a big challenge so i want
you to give me your entire concentration
force and i'll see you in a bit
okay so
first thing we're going to do is we're
going to
unbox this
and we're going to delete all the
unnecessary things we have up here
so let's go ahead and delete all of that
zoom back in go to our inspector save
that
then
let's go and create an empty game object
and make this smaller we didn't don't
need it that big
click on that to remove
make it a little bit bigger and we'll
call this game object our player
and this player will be reset to
the middle of our screen
and honestly this is the most exciting
part of all game creation
when you start making your player
so
let's go over some technical words
animation 101
first first thing you need to learn is
an animator controller so an animator
controller allows you to arrange and
maintain a set of animation clips
you'll see what that is in a bit
an animator component used to assign
animation to an game object in your
scene so if you have a game object and
you wanted to have animations you assign
it an animator component and that
animator animator component gets an
animator controller it's a bit confusing
we'll see everything animations it's
several sprites rendered one after the
other so it's a set of sprites one after
the other we put them next just like
video works where it's a set of images
one after the other and finally a sprite
renderer we've talked about it
previously renders a sprite for 2d
graphics
okay great so back to unity
and from unity we are going to be
importing the sprites i've left you in
their resources for our human
so let's go ahead and go there and here
you can find that we have fall idle jump
and run so we'll use for now either
animation but in order to create the
other animations we have the run and
fall jump
so click on the idle and drag it into
our unity so we have it right here i'll
actually we don't want we want it inside
of sprites
so let's close that and now let's create
a folder
first for our
conqueror we'll call this conqueror
and our conqueror will
have this sprite first thing we're going
to do is we're going to be slicing up
our
conqueror
but before we do that i want you to
understand the steps that we are going
to take so
we are going to import the conquerors
sprite sheet and slice them up we are
going to create the player object we've
already done that and add a sprite
renderer to it we'll do that right now
we'll create will create an idle
animation
we'll add an animator to our player
we'll create a plan player animator in
order to add all the animations to it
we'll add an idle animation to the
animator and will assign the animator to
our player
so let's go ahead and do all of those
things
first thing let's slice up our player so
we'll go to multiple
we'll make the pixels per unit 32
and we'll apply all of that we'll go
into our sprite editor
so as you can see here we have one two
three four five six seven eight nine ten
eleven sprites and they are spread over
800 here below you can see it 858 by 58.
if we do automatic slicing
you can see that it does the job pretty
well but the problem is that when we'll
be adding other animations to our
conqueror
we'll have a slight problem with that
that's why i'm going to slice it up
in a manual way
and it's going to be 58 by 58 we slice
that up and as you can see it's not very
accurate
why is that because we want to have some
kind of offset
why we need that offset well because 58
by 58 just doesn't cut it
and we are going to pad
let's do a padding of oh i mean an
offset of 20 nope i meant padding so
padding of 20
and now we can see that they are all in
the middle the most important thing is
to have our conqueror inside in the
middle of the sprite so all of them are
in the middle and okay great so
slice that up apply everything
you can as always i've told you you can
rename them if you want to go down that
road so
we've sliced up our sprites now it's
time to add our renderer the way we do
that
is we'll move this up here and we'll add
a component and it's going to be a
sprite renderer and in our sprite
renderer we have this default sprite
choose any one you'd like and put it
inside of it and we have our player
great
so now what we need to do is we need to
add an animator to that player or
actually an animator component that
we've talked about so let's do that
simply type in
animator
now we have an animator controller and
this object can now begin to have
animations
back into assets let's create a folder
we'll call this folder
animations
and inside of animations we are going to
create an animator so animator
controller and we'll call this the
player
now
let's get back
what should we do right now okay so next
step is going to be we're going to open
up our window for an animation so go
into animation and click on the
animator window animations animator
and we have the animator but we are
going to dock it in a different way feel
free to dock it however you want this is
my personal style so i'll dock the
project and console next to each other
and i will dock the animator
wait of
what and i'll dock the animator right
here below oh okay you need to
do a couple of restructuring right here
just like that and it's perfect so
this is our animator right here below
our scene and we'll add also a window
for the animations
so animations and we'll dock it next to
the animator
just like that okay great
next thing we're going to do
is we're going to create an animation
and we'll be adding it to our animator
so as you can see we already have a
couple of states these are called states
this is the entry state this is from any
state and this one right here is an exit
state
so let's create an animation the best
part of our game
so go back to sprites conqueror and the
way we create animations is we choose
all the sprites that we want so as i've
told you before click on the first one
go to the last one hold shift click on
them you've chosen all of them
right click on it and go to create and
go down into animation so this will
create an animation
and we'll call this idling
idling
okay great now we have an animation of
idling for our player simply drag that
into animation and inside of animation
we have to now add this
idling animation to the animator so we
do that by simply click on
click on the id and drag it into the
animator and now we have an idling
animation for our player
one thing we also have to make sure of
is we click on animation and add a loop
time because if we don't he'll do this
animation once and then stop but idling
is an animation that we want to have
over and over and over and over so click
on that
save all of this
and don't forget to go to player
and in the animator controller it will
ask you for a controller you can either
drag this
here or you can click on the little
circle and add the player animator save
that
and now let's click on play and see what
we've done or if anything works at all
so
if we go back to scene we can see that
our player moves and he
is idling
whoop okay great
very exciting
it is very exciting but there is a
problem if we take our player right now
and drag them into our platform
we cannot see anything so where is he
what's the problem the problem is
well it's actually your problem because
see what i did there i actually changed
the
everything the steps into a
challenge because maybe you're just
watching and not doing anything so this
is your chance to do the challenge so
your challenge is to do all of the
things that we've done already you can
re-watch it maybe you already doing
everything with me and pausing the video
but if you're not now is the time
and your extra challenge is to use the
sorting layers to make our player
visible in front of the background so
we've covered sorting layers before i
think you have enough skill to do all of
them and i'll see you in a bit
welcome back i hope you did your best in
that challenge i hope you just didn't
stare at the screen
so we'll choose player we'll go into
sprite renderer and we see here that we
have the sorting layer just as we had
for the foreground and background
so if we click on default we don't have
a player and we can add a sorting layer
so let's go ahead and do that
so a new layer will call this the player
layer
player layer that's fun to say and we'll
put it in front of background and behind
foreground even though he will not be
going
over the foreground or behind it but
we'll render it that way
save all of that
back to player and choose the sorting
layer to be the player so now our player
our player is on the player layer
save that 10 times and now
i actually i think that our player is
just a little bit small i think we'll
make him
bigger so let's go into sprites and the
way we do that we choose the
conqueror sprites and we'll make this
30.
so if we make this 30 click on apply he
becomes just a little bit bigger just so
he can be seen better and if this camera
logo in here is bothering you it's
bothering me you can actually click up
here on the gizmos and you can make all
the icons smaller you can even make them
disappear
okay great so i hope you got on with
that challenge i hope you are excited as
i am because our player is actually
moving and we have
breathed some life into our game i'll
see you in the next one
hey there
this is michelle from the future sorry
to interrupt but i want you to do
something that we haven't been doing so
far and that is committing our changes
maybe you've been doing that and i
congratulate you
but if you're not this is a great time
to start doing so as you can see i've
been doing it each video so slicing up
sheets creating entire palettes created
a platform added rules and now we're
going to add the animation
so we'll commit that change and
adding
animation or adding
idling
animations
so if you haven't been doing the
repos right here this is a great time to
start because we are going to be doing a
lot of things in the upcoming videos
so i'll see you
[Music]
welcome back my fellow game developers
to a brand new video and this one is
very exciting because we're going to be
learning about another other animations
and even more transitions so as you can
see here in our animator we've added two
new states which are climbing and
running and we've added transitions
between them we've also added parameters
that will allow us to make those
transitions and now if we click on play
we can actually take our player from the
idling animation into the running
animation and we also make a climbing
animation from what we have so i'm very
excited for this video i hope so i hope
you are too so let's get into it
okay first thing we'll do is we'll go
and add the sprites for running and the
climbing
so for the running we have this run
sprites and for the climbing i'm going
to use the fall and the jump because we
don't have
the actual climbing animations but i
wanted to include that in our project so
go ahead click on all of those
and drag them into
our unity so
we have jump we have the idle the run
and the fall for now let's just focus on
the running so as you know this is a
step that we've done multiple times
let's go ahead and click on run
make it multiple make the pixel size 30
because as you remember we've increased
the size a bit
save that and yes i meant to apply
go back to run and for some reason okay
so go into sprite
editor and we have those sprites let's
go to grid by cell size
it should be 58 by 58 with a padding of
20 as i remember yes exactly
okay so apply that now we have our
sprites
let's go ahead and click on all of them
as we did before check all of them right
the click
go to create
animation and we'll call this
running so running great
close that take running into animations
and later on
we'll create a folder
so now let's add the running animation
state
to our an anime tour so at running right
there so now
this is a bit tricky but let's zoom in
move that exit
exit to over here
and now we have the idling and the
running next to each other
so how are we going to tell our animator
that we want to transition from the
idling into the running well if you
right click on idling you can actually
make a transition so make that
transition and push the arrow into the
running
and if you click on that transition as
you can see we have lots of options and
lots of settings also
so let me tell you just a bit here
let's talk about transitions we have a
bit of blending here between the
animations but we don't want that so as
you can see we have this blending right
about here and we can actually
remove all that blending so it goes
immediately from idling to running and
we'll do that because we already have
very good 2d animations so we can simply
go into transition
duration and put it to zero that way
there will be no lag between animations
so now we have the idling going to
running but how is it going to know that
we actually want to go down that road
well we do that using the parameters
here on the left so go from layers into
parameters and as you can see we have an
empty list
so here is where we start adding
parameters and we can add a couple of
parameters we can add a float an integer
a boolean or a trigger for now we'll be
using a boolean and that boolean will be
called
running so if we want to transition into
running we'll need to use the running
boolean
and in order to add it
under the if we click back on
transitions we have the conditions right
here and this condition list is empty so
we click on plus and it it automatically
adds the running because we don't have
anything else to add and now if we click
on play
we can see that we are right now in the
idling and if we click on this boolean
we go into the running but it does
it does it only once why is that
i'll give you a mini challenge right now
to figure it out
okay
enough so let's see running should be in
a loop
save that
back into play and now if we click on
the boolean he starts running and he
keeps running
forever
why is that we want to make this better
so we'll add a transition back from
running to idling and this transition
will also have
an a duration of zero
and its condition right here will be
running but when it's turned to false
save that again
click on play
and now our player is idling and now
he's running and now he's not running
and now he's running
and now he's not running haha
okay so this is very cool this is very
exciting
and this is a great time for your
challenge so your challenge is to create
the climbing animation so import the
climbing sprites from resources
slice them up and size them
appropriately
create a transition from idling and to
running and finally create a trigger for
the transition so pause the video right
now i given i've given you all the steps
that you need
i want you to try your best
so i'll see you in a bit
welcome back so how did you get on with
that
let's go ahead and do the challenge so
first thing we'll do is we'll go into
our conquerors sprite and as i've told
you we'll be using the fall and the jump
animation in order to create our
animation so this will be a bit tricky
and now we'll go into our file
so our fall should be
32 and we'll make it multiple even
though we don't need to do that but
because we're going to slice it up
our way
so it's 58 by 58
apply we only have one sprite and in
here also we have only one sprite
so apply that don't forget to make it 30
not 32 so 58 by 58 sliced it up apply
great so now we are ready to use
these two so let's click on those right
click and create
an animation and we'll call this
climbing so climbing animation back into
our animation folder
and we'll add it into our
animator will create a transition from
idling to climbing and a transition from
climbing to idling will also turn off
all the transition duration on both of
them
and we'll create a new parameter which
will be a boolean and we'll call this
climbing
so climbing
and now we'll add this condition to
from idling to climbing the
climbing should be true and from
climbing to idling the climbing should
be
false
save that click on play
did we put it into loop i'm not sure
let's try it so climbing and it stops
because we haven't put it into
looping save that again and now
if we click on climbing he starts
climbing but as you can see it's kind of
super fast so let's go ahead and
play around with our animation how do we
do that so
we have an animation tab right here that
we haven't used yet so go from animator
to animation and as you can see here we
have this climbing if we click on player
up in the hierarchy we have the idling
we have the running and we have the
climbing and if you click on any one of
those for example idling you can see
that it tells us which things change
during the animation for example here
the thing that is changing is the sprite
so we can actually take it frame by
frame or play it right here and we can
see that our
player moves with the idling and you can
see every single frame
and and you can go forward and backwards
make it smaller make it bigger
so we'll use that for the climbing why
is that because as you saw the climbing
is extremely fast and we want to slow it
down just a little bit
so how are we going to do that
well it goes from here to here so we'll
add another one so copy that click on
ctrl c
go to the frame with in where you want
to put this
sprite and ctrl v
okay so now we have these two
well actually let's choose both of these
and ctrl c
ctrl v and then again
so it's three times let's make it one
second
okay let's see how that works click on
play
it's a bit fast still
but at least he does it multiple times
we can actually
let's take them apart if we choose all
of these and let's you know what let's
delete the last two
and choose all of these and we actually
can
spread them out over a second and now if
we click on play
it will be just a little bit something
is wrong right why is that because the
last frame well actually they're not
spread out correctly so let's spread
them out correctly so this is on four
six
eight on the one and the last frame
should be the same as the first frame so
let's put in
that one and now if we click on play it
should be very very smooth
so
a final step before we go i want to go
into
player i want to go into the animator
actually and i want to remove the exit
time as you can see we have something in
here that's called exit time
and this is used when you want to
transition back into the previous
animation or go into the next animation
after a certain time and we don't want
this right now we'll be using it in the
future so go into every single
transition
and remove the exit time
and we are done so let's save that let's
click on play and see what we have
so we have our player idling
and if we click on running he starts
running and we unclick on off of running
he stops and he also climbs
how cool is that seriously this is the
coolest part and i hope you enjoyed the
video i hope you learned a lot and don't
forget to save in the repo
and i'll see you in the next video
[Music]
welcome back everyone just wanted to
remind you of the amazing job you've
been doing so far in this video we'll be
adding a rigid body and a collider to
our player we'll also be adding
collisions to our environment as you can
see here that will make or enable our
player to land on the surface of our
foreground so now if we click on play
our player actually stands on the
surface so let's get started
okay so let's start off by adding a
rigid body to our player but before we
do that i think it's a great time for us
to prefab our player so to do that let's
go into our assets right click and
create a folder and we'll name this
folder
prefabs
let's go ahead and prefab our player so
now we have a player prefab which feels
good
so
back to our player let's go ahead and
add a rigid body to our player so
rigidbody
2d
and we'll make sure that we have it as
dynamic save that
and apply it to our prefab
the way we do that is we go to overrides
click on down and there will be an apply
all okay great before we continue i
wanted to take a second and talk about
rigid bodies to the e one more time so
it's a component added to a game object
that subjects it to it should not be tp
it should be two physics engine forces
and we have
many body types of rigid body 2d so we
have dynamic which has finite mass and
is affected by gravity and other forces
we have kinematic that isn't affected by
gravity and other forces and we have
static which behaves like an immovable
object
okay great now
back into unity and because we have a
rigid body
now if we click on play
our player falls through the ground okay
not very helpful but it's a step forward
so now it's time for your challenge it's
a bit of an early challenge but i think
you have it covered so we've talked
about collisions before so now it's time
to add the appropriate collider to your
player
you need to add a collision to the
environment and you have to make sure
that your player lands on platform
without falling through so pause the
video right now if you feel that you
have the skills to do that if not
wait a couple of seconds and i'll be
right with you
okay so colliders they are very helpful
so go into player let's close down this
rigid body
and let's go ahead and add a collider so
i think we'll be adding a box collider
2d to our player and as you can see
our play or our box collider is a bit
too big for our player so we'll go ahead
and shrink it down
and you can do this however you want it
depends on your preference to the game
how much you want to make the box
collider big or small but what you need
to keep in mind is that his feet should
be touching the bottom of the collider
so let's make it
this big
and this is simply based on your
preferences i like to keep it just
smaller than his actual size
to make the game a little bit fair so if
you make the box collider bigger
that will make the game a little bit
more difficult and if you make it
smaller it will make it easier for your
players so
i think this is good enough so save that
and as always go to override and apply
to the prefab so now if we click on play
our player still falls through why is
that well because we don't have any
colliders on our foreground so let's go
and add some so go into foreground
and if you got to this point and
couldn't continue don't worry about it
because this is something new we'll be
adding a tile map collider so let's go
into tile map
and as you can see all of the foreground
tiles have been
have now a collider on them but the
problem is that if you zoom in you can
see or you can't but if you zoom a lot
you can see that there is a tiny tiny
tiny gap between the colliders and
believe it or not this will cause
problem for us later on especially if
the player is moving or dropping down at
a very fast
velocity he can go through these
colliders so how are we going to fix
that
well there is a small solution
that is called a composite
collider 2d so let's see what that does
so composite
collider 2d when we add that it
automatically adds a rigid body to our
foreground
and what this does it actually
let's close this and if we click here if
we look into our tile map collider we
can see that we have a check box that is
called
used by
composite and what this does if we click
on it
you can see that all of the
colliders are now
on a single collider but we can't see it
let's
make this bigger okay so now you can see
that we have a single line of collision
to our foreground so now if we save that
oh and there is one more problem
well you should have thought of it maybe
you didn't that's okay i've missed it a
lot of times because we have a rigid
body on our foreground if we keep it on
dynamic all of the world will be falling
down so we need to change this from
dynamic into static that way it stays in
its place whatever happens so save that
click on play
and now our player stands on our
foreground
now the game is becoming more and more
realistic
so
this is
great this is a very big
leap forward
but there is one other problem because
if we click on our player and we set him
here on the edge
and click on play
we can see that he actually
falls on his head and now the animation
is placed
well it is kind of cool you know but we
don't want that so in order to avoid
this type of behavior from our player we
can actually go into our
not rigid body excuse me we can go into
i mean into our rigid body and down here
we can see that we have something called
constraints
so this constrains the movement of our
player on
certain uh
rotations for certain rotations so what
we want is to freeze the rotation on the
z axis if you look here at the top of
the transform if we use the z rotation
our player rotates so this is the one
that will be freezing
okay great is it still freezed
do we need it to override apply all and
now let's close that
why is it telling me that i need to
change my collider okay click on play
and now our player
stands using his hammer it's not very
realistic but
it's
a 2d platformer and it's okay we don't
need it to be very realistic so i hope
you enjoyed the video i hope you try to
do the challenge and i'll see you in the
next one
hey
congratulations on making it this far
you are doing extremely well
i'm not there sitting with you but i'm
pretty sure and if you got to this part
you are doing extremely well
so i hope you're enjoying keep on going
we still have a lot to learn so see you
in just
[Music]
welcome back to another video and the
start of a new chapter in our game
development journey in this video we are
going to start moving our player based
on keyboard
input will be using the same formula as
we did for the previous project or for
the magic game cube but with a different
twist to it that we'll see in a bit so
as you can see we press on the right
arrow he moves right we press on the
left arrow he moves left and i'll see
you in a bit
okay so as the title suggests we want to
manipulate our game objects behavior
so what does that need well that needs a
script and that means coding which is
very exciting and a bit scary so let's
go ahead and add a script to our player
where is our player we already have him
so let's go to add component and create
a script that we will call
simply player down here we have new
script and we'll create and add a player
script wait for it to understand what is
happening
and okay so
let's start
by creating a folder one of my personal
favorite things to do
apparently so scripts scripts
and we'll add the player into our
scripts great let's double click on that
that
and let's wait for visual studio to open
up and understand everything okay so
i wanted to initially do
the initially do the challenge later on
but
i think i'll do it just now so if you
are ready
you can take the initiative and move
your player first thing you need to do
is import a cross plot for platform
input asset package that i've provided
you in the resources
then you create a run method that is
called from inside of update
then inside of run use the rigidbody to
move the player
and finally add a variable to control
our speed so it's a bit of a daunting
task if you think you have enough skills
to it go ahead and pause the video and
try it if not and you think it's too big
of a mountain to climb wait for me i
will do it in front of you and one more
thing if at any point you feel that you
can continue it alone i recommend that
you pause the video and you do it so
i'll see you in just a bit
okay
welcome back so
maybe you've tried to
add the cross platform input from the
resources i provided you but you can
also go into unity's asset store and
search for standard assets which has the
cross-platform input inside
what is cross-platform input well it's
something that we'll be using instead of
input and it literally does what it says
what's next what name it is well it's
cross platform input that means it's
across multiple platforms so this game
that we are creating right right now
could be on a
computer on a
pc
or maybe it can be on a playstation 5
that's coming out recently
but of course like this is isn't going
to be a playstation 5 games but who
knows maybe you could create a
playstation 5 from this simple graphics
anyways let's go ahead and import the
cross platform package so simply go into
the resources and drag the cross
platform package into our assets
it will ask you
to do you want to import all of these
simply click oh what is this okay don't
worry about that we've already imported
that and what we do need
is
the standard assets so go ahead look for
cross platform
on that and now simply click on import
we only need the cross platform
assets and if you've downloaded the
standard assets from
the internet
also only choose the cross platform
there's no
bad thing to do well if you import
everything but for now we just need the
cross platform so
wait for that to import and now we
should have a folder that is called
cross platform
folder and let's go ahead and add the 2d
extras which is under the file
7.15 whatever into our standard asset
to make everything a bit more
cohesive as i'd like to say
save that
let's go back into visual studio and
because there is a file modification
detected it will ask you for a reload
simply reload
reload again it shouldn't do it anymore
everything is fine okay
so
first thing we are going to do will be
adding a
using
cross platform
that means at the top here
uh i'm not sure i've explained this
enough
these are the libraries that we are
using for example the unity engine
is
the library for the start and the update
and all other
unity related things
that we use in our script so now we have
to import the cross platform library and
we do that by typing using
unity
standard assets dot cross platform
inputs
so now we have access to the cross
platform input
next thing we're going to do is we're
going to create a run method this will
be a private method it will not return
anything that means it's a void and it
will be called
run
and what should we do inside of run well
we're going to use the get access method
and get the horizontal so
well first thing we're going to do is
we're going to put it inside of a
variable so it's going to be a float
it's going to be
let's call this
control
throw
and it's going to be you using instead
of input we'll use cross platform input
manager it's a big word but it's what we
use instead of input it's going to use
dot get
axes now inside of get axis we'll need
string name for our inputs and where
will we get that
well let's go back into
unity here and if we go to edit
and we look for project settings
we can see that we have our input
manager that opens up and if you don't
have it opened up simply click on input
manager so this is where we have our
project settings there are a lot of
things in here we don't need to go over
all of them
so for example we have physics 2d which
we'll be using very soon but for now
let's focus on input manager we have
these axes here and if we click on that
we can see that we have a lot of options
so and one of them is the horizontal so
horizontal is when we click on the a or
d and this is exactly what we need so
because
in here the get axis needs a string
reference
we'll go back into the input manager and
every time we have a string reference we
always go and copy it we never assume
that we've written it correctly
because we never do and we cannot find
the error so
we have a control throw and why did we
use a float variable to catch this input
because i will demonstrate it so if we
click here print
and we'll
let's go where is it control throw let's
print that out and see what happens and
let's not forget to call it in the
update method so save that
back into unity
let's dock this here next to
our tile palette
that's i think is a good place
and now if we click on the play
and we click on the left ma on the left
arrow you can see that it slowly goes
from zero
to minus one and then back to almost
zero and if we click on the right arrow
it goes from zero slowly to one and
that's why we need to save it inside of
a variable to always have control over
it so now that we have it let's delete
this print right here
it was only to demonstrate how this
works
next thing we're going to do is we're
going to create a player velocity of
vector type 2.
so
we'll do that by first getting the rigid
body
so let's create a variable right here
that is the rigid body so
it's a rigid body 2d i will call it my
rigid
body
2d
and previously we've used we called this
a public variable and we've added it
from the inspector but now i'm going to
teach you a much better and
maybe more efficient way to do that in
code so the way we're going to do that
is and start we're going to call our
variable
and we're going to assign to it
the rigid body that is currently
sitting on our player game object so
we'll use get component
which gets a certain component and what
that component is
well it's a rigid body 2d
and that is how it's written now we have
a reference to our rigid body to
d
and let's go ahead and change it and
run so
we'll click on here it's my rigid body
2d now before that let's create a
variable for our place velocity
and that variable is going to be a
vector 2
we'll call this player velocity
velocity
and this player velocity will be equal
to a new vector 2
and we'll move we are moving this in the
horizontal axis
so
we will only be changing the velocity in
the x or horizontal direction so this
will add the controls row to the x
axis and to for the y we'll simply keep
it as my rigidbody
dot
velocity
dot y so in the y direction the velocity
will not change and finally we'll assign
the my rigid body to the dot velocity
will be equal to the player velocity
that we've currently created so save
that
let's go back into unity and see if we
did anything correctly so
click on here our player falls if we
move left
he slowly moves to the left and if we
move right he also slowly very slowly
moves to the
right okay
excellent
as you've seen he moves very slowly and
we'll need to fix that in order to do
that we are going to create here a
variable for the run speed so
let's go ahead and create something we
call a serialized field oh very
scary
some fancy words you using michelle
don't worry i will explain what that is
and serialized field is just like public
where we can change the variable from
our inspector but the only difference is
that we can actually manipulate that
variable from a different script
okay so like we use public functions to
change
well to use functions from different
scripts we can actually use serialized
field to change variables and i don't
think we'll be using it too much but
let's say for example you want to change
your player speed for example depending
on the platform you're standing on you
can go ahead and do that using the
serialized field
okay small explanation let's continue
we're going to make this run speed a
float and we'll call this simply run
speed
and what should this run speed be
we can actually do
something let's try 10 f
and we are going to multiply it with the
controls row right here so run speed not
run
actually let's run speed
and now
if we go back into
unity
and click on inspector
then click on player now we can see that
we have a rans run speed of 10
so we go into play mode
we can move now with a speed of 10 and
we can actually increase this to 100 see
what happens and our player what did you
see did you see what just happened you
see how our player disappeared or
actually you can still see him right
here in the bottom left corner don't
worry about that we'll see a couple of
more instances of this but we'll be
fixing it later on in the other videos
so
i hope you enjoyed uh
this is the part where our player comes
to life and we start manipulating him
using code and everything is fun
everything is very cool i hope you
enjoyed and i'll see you in the next
video
[Music]
welcome back everyone our player now
moves in the game but the problem is
that he does a moonwalk so whenever
we're moving backwards he does not flip
he simply does a moonwalk and we don't
want that in this video we are going to
be flipping our player so if we click on
play
we can see that whenever we move to the
right we move right but
when we start moving to the left we
actually flip our player and now he
moves in the direction and actually
looks in the direction he's moving the
correct one so
very exciting let's not waste any time
and let's jump in and get started
okay so
how are we going to flip our player in
the direction that he is moving
first thing we're going to do is we're
going to apply all of our changes to the
prefab so if we look closely at our
player we can see that he moves left and
right but he does not flip
how are we going to go about this
if you go up into our transform you can
see that we have position rotation and
scale
so scale if we increase the scale of our
player in the x direction you can see
that he gets bigger and bigger and
flatter and flatter but if we reduce it
to
0.3 he gets smaller but what happens if
we go beyond the zero if we go to minus
territory we can see that our player
flips
so at minus one our player is facing the
other direction and this is what we are
going
to be doing but in our code depending on
the direction our player is heading in
and we'll do that using math but not
very hard math if you don't like math it
will be simple
math
okay so
now let's go into our visual studio and
let's go ahead and create a function
that will call
private
void
flip
sprite script
sprite so we have flip sprite
and we are ready to go so flip sprite
before we start i need to explain two
concepts first of all math.apps
so i hope you remember from school what
absolute value means
it means it returns the absolute value
of something so for example if we have
math dot abs minus 4 it returns 4
and math dot sign so what is math.sine
it returns the sign of a certain number
that means if we have math sine minus 4
we have minus 1 as a result and if we
have math sign 4 we have plus 1 as a
result so this is a quick overview of
overview of first grade math or
something like that
let's go back
and let's go ahead and create a boolean
so
so i went into visual studio so in this
we are going to create a boolean which
will tell us
if our player is actually moving
so
let's go ahead and create a bull
which will be
running
hori
running horizontally
not sure if horizontally takes two s or
just one
or actually horizontal the a is not in
the right place okay so horizontally
equals
math
dot
absolute value
my rigid body
to the dot velocity
dot x now you might be wondering why are
we even using the absolute value of our
rigid body's velocity well because when
we are moving in the
left direction our velocity is negative
and we are when we are moving in the
right direction our velocity is positive
so we need to take the absolute value to
make sure that we always know when our
player is moving
and to make this boolean because right
now it's not boolean we're going to
check if it's bigger than
wait for it math
f dot
epsilon okay now
again michelle you're using very scary
words what is math dot epsilon so first
of all when we type math.f that means we
are accessing the library of math where
we have a lot of functions and a lot of
methods to use and epsilon is not a
method nor is it a
function it's a
a small number a very very very small
number like say for zero and
four or five zeros after it and one so
why are we using math dot epsilon why
not simply compare it with velocity
equal zero if you remember in the
previous video when we tried to print
the control throw you can if you
remember whenever we went to the left it
slowly moved from 0 to
-1
and then it went back to minus 0.009
it never went back to absolute zero
that's why we are using math f dot
epsilon instead of
simply using zero
next thing we're going to do is we're
going to use an if condition so
if
running
horizontally
and inside this if condition
i'm going to issue you a challenge and
your challenge is to complete the if
statement so we are going to flip our
players sprite based on the direction
they are moving
and let's i'll give you a couple of
hints one will use
transform.localscale and that's how you
access the scale of a game object
and you will be using use math f dot
sign to determine the direction
in which our player is
moving so
pause the video right now give it your
full concentration your full thinking
ability and do the challenge i'll see
you in a bit
okay welcome back so what should we
write inside of our if condition so
it's
transform
because we need access to our transforms
local scale
and this local scale in fact is a vector
2
because it's 2d so we'll be
using the scale on the x and y so it's a
new
vector 2
and what should be right for the x and
the y scale should stay the same that
means it's going to be
one f
okay
but what should the x be
well the x will be depending dependent
on the direction so we're going to write
math f
dot
sign because it depends on the sign of
the direction
and what direction is that it's the my
right body dot velocity
dot x
so now
save that so now
if our player is moving to the right the
velocity will be positive and the sign
will be positive our scale will stay one
but
if the player's velocity is to the left
that means the velocity is negative that
means the sign is minus one and that
means that our local scale
x will be -1 so let's see if that works
save that and a small mini challenge i'm
going to give you right now
where do we actually use this flip
sprite
where should we put it inside of our
code to flip our player
i'll give you a second to think about it
one mississippi
two mississippi
three mississippi okay time's up it's
inside of run because we're only be
using the flip sprite whenever we are
running save that go back into unity
let's move out of
the camera click on play and now if we
move right we move
right if we click on the left arrow we
actually flip and how cool is that
okay great so i hope you enjoyed the
video i hope you did the challenge and
i'll see you in the next one
[Music]
welcome back everyone to a brand new
video and this video we are going to be
changing our players state from our code
so as you can see right now we have our
player in the idling idling state as
soon as we start the game and if we move
him left or right you can see that his
state changes into running and if we
stop he changes back into the idling
state so let's not waste any more time
and let's get started
okay so let's start off first of all by
re-explaining what is happening in our
animator first off we'll make it a bit
bigger and zoom in
so first thing we'll need to take notice
of is here in entry
from entry we have a transition directly
into idling and what this means is that
as soon as our game starts we go
directly into the idling animation
and from there we have two options or
two states to go to we have the running
state and we have the climbing state and
both have transitioned to and from so
for example to go from idling into
climbing we can see that we have this
white arrow line
that has a condition on it and that
condition is for a boolean to be
a boolean called the climbing to be true
and in order to go back from the comedy
climbing state or animation this
climbing condition needs to be false and
the same holds true for running so the
transition from idling into running
needs for a certain
boolean to be true and to go back from
the running state we need a certain
variable or a parameter which is running
to be false
so how are we going to do that using our
code well first of all because the
parameters are present on our animator
what we need to do is get a reference to
our animator so let's go into visual
studio and try to do
just that so
here we are in our visual studio first
thing we'll need is a reference to our
animator and we'll do that the same way
we've done to get a reference to our
rigid body so let's go ahead and create
a variable
for our animate so we'll create an any
meteor animator please so an animator
will call this my
animator
and we'll use the get component to get a
reference to our animator so get
component
animator
and close that up save that great so now
we have a reference to our animator next
thing we'll need to do first we'll be
focusing on the running so how will we
change
from a
idling where is that so from idling into
running how are we going to change that
well we'll have to set the boolean
because we know that it is a boolean
let's go back
and in running when we start to run
let's go ahead and
go into the running state
so we'll do that by using my animator
which is our reference dot
and it has multiple
methods attached to it and one of them
is the set
bool and this allows us to send it a
reference actually it has two
ways of giving it parameters the second
way is our way which gives it a string
and the boolean value that we wanted to
have so the string reference name and
the bool value which can be is either
true or false so let's do that first
thing we'll need the string name
and because it's a string reference
we'll simply go back into unity double
click and copy that
reference
because as we know whenever we have a
string reference we always always go and
copy it and now we need to set the value
for it and of course it's going to be
true now this is not the final solution
by any means but this will demonstrate
how the set pool in my animator works
so let's go back into unity and see if
that worked if we click on play right
here
our player goes into the running
animation
it's good it's not bad
at least we know it's working but this
is not how we want it we want it to go
back to idling whenever we stop the
running state
so
that is going to be your challenge and
your challenge is to stop the running
animation
so you need to add to our run method
a way to stop the running animation and
that means going back to the idling
so it should stay true while the player
is running and falls when the player
stops
use the code we've created when flipping
the sprite so
pause the video right now and go ahead
and do the
challenge okay welcome back so how did
you get on with that i hope it wasn't
very hard
or i hope it was at least a bit
challenging so
let's see what we need to do well
because i've told you we'll need to use
something from the flip sprite method we
are going to check if our player is
actually running and we'll do that by
simply copying the following line which
checks if our player has a velocity
on the horizontal plane
so now we have a boolean for
running horizontally
and what we can do because this is
actually a boolean and it's true
whenever the player is running and false
if the player is not running we can
directly set it right here in our
animator so we'll replace that with no
sorry i mean running
running horizontally
and let's do one more step and that is
extracting this method method
into an outside one because it's just a
bit different we'll call this
changing
to
running state
and now we save all of that we have a
our changing to running state which
checks if our player is
moving in the horizontal plane and if he
is that means our running horizontally
is true that means our animator sets the
running to
true and if he's not
running this running horizontally will
be false and hence
our animator will suddenly running
to false so let's go ahead and see if
that worked click on play
our player is initially in the idling
animation or state and now if we move to
the left he starts his running if we
stop
he stops and goes back into idling
great so
this is the foundation of controlling
our animations from our code we set up
our state machine
we have parameters which we can access
in our code when a particular thing
happens we can manipulate those
parameters using our
code and changing the player state i
hope you enjoyed the video and i'll see
you in the next one
[Music]
welcome back my favorite game developers
in this video we are going to add the
ability to our player to jump so as you
can see he can now reach platforms that
were
unattainable before and he can jump from
one platform to the other and as you can
see it's very snappy it's very exciting
and it's going to be very very fun so
let's not waste any more time and let's
jump in and get started
okay so
first i want to talk about the jumping
mechanics and how they are
so
the jumping mechanics will be a bit
different than the running mechanics why
is that well because running is
different than jumping
while because when we run we actually
pick up speed slowly but when we jump we
technically
immediately have a velocity upwards so i
just want to show you
how our
velocity actually increments so if we
bring the
player velocity to our console right now
let's go ahead and try that
as we start to run with our player you
can see that it's zero zero when we
start running to the right it increments
slowly from zero to nine point seven
nine 9.8 and eventually to 10
then goes back to 0 and and the same
goes when we click on the left arrow but
we don't want that in our game we
actually want our player to immediately
jump as soon as we press the space bar
or whatever button we would like it to
be pressed
and we'll do that using a different kind
of function than the get access we'll be
using the input dot get button so if you
read the description right here you can
see that it returns true so it's a
boolean it returns a true during the
frame the user pressed down the virtual
button identified as button name anyways
what you need to take out of this is
that it immediately
turns something into true and then back
to false if we pressed a button and
that's what we're going to use and of
course instead of input we'll be using
cross platform input manager
because as we as we've said before we
want this to be a multi-platform game
and let's jump in and get started with
it so first thing we'll do is we'll
remove this print because it's done its
job it's finished its service
and we're going to create a function or
a method right here which we'll call
simply jump and now if we save that we
have the option to extract we have this
little light bulb light bulb on the left
click on it and click on generate method
don't worry about whatever is written
already inside of it it's a private void
method just as we want so
what are we going to do
well first thing we're going to do is
we're going to
use a well create a boolean and that
boolean is going to be called is
jumping and that is jumping is going to
get an input from the cross platform
input manager
and we'll use the function that we just
described the get button down so let's
open that up open it up and we can see
that it takes a string
reference as an input
so let's go ahead and find the string
reference of the jumping input
we go into project settings that that is
docked here on the right so click on
that
make this a bit bigger
and let's scroll down and see where we
have the jump there it is so it's jump
and it's positive button is space
so let's copy this because it's a string
reference and as we've said before
whenever we have a string reference we
always always always go and copy it so
now we have the is jumping boolean set
and ready next thing we need to do is
we'll need to add velocity to our player
in the y direction
so let's go ahead and do that so
we'll create an if condition
and if
is jumping
that means if our player has pressed the
jumping button we'll create a vector2
we'll name this jump
velocity
and this jump velocity will be equal to
a new
vector 2
and in the x direction we'll only have
my
i mean my rigid body so my rigid body 2d
dot velocity
dot x
and in the y direction we will want to
add
a velocity speed for jumping and this
will be dependent on your preference it
could be 5 it could be 10 it could be 20
and whenever we have such a
variable well when we have something
that is variable it's much better to
create a variable for it just as we did
here below for the run speed so let's go
to the top and create a serialized
field and serialized field is something
that we can adjust from different
scripts maybe we won't need it right now
but let's just go ahead and make it a
serialized field
so it's a float
what float and it's go we're going to
call it
jump
speed and initially let's go ahead and
make it 15
15
f
because it's a float so 15 f
and let's add it to our jump velocity
okay great and as a final step we need
to
add this velocity
jump my rigid body dot velocity
velocity is equal to our jump um
jump
velocity okay great so save that let's
go back into unity and see if that
worked make this a bit smaller click on
play
and now we move left and right and if we
press the space button we can see that
we jump but that jump is a bit
floaty as you can see but at least it's
a start it's a huge leap forward in our
game development journey get it leap
forward
okay i will not make the joke again so
let's see what we can do in order to
make this game a bit more snappy
so
we can see here that we have a physics
2d option in our project settings and
what this allows us to do
is that allows us to adjust the physics
to the of our unity engine and we have
many many options to adjust we have
maximum rotation speed we have
translation speed we have angular
correction we have a lot of stuff in
here i will leave a link in the
resources to go check out the physics 2d
in the unity documentation you can go
into every single detail that you want
but for now we're only interested in the
gravity right here and as you can see
our gravity currently in the x direction
is 0 and in the y direction it's minus
9.81
which is exactly the same gravity that
we have here on our planet so if we
click on play
and we jump we can actually adjust this
right here so if we make it for example
-27
now if we jump
we don't jump as high as we did before
so this is where we begin to tune our
jump depending on how high and how
snappy we want our game to be
and a small reminder whenever we finish
adjusting something in our play mode if
we unclick from play you can see that it
goes back to its original value so keep
that in mind
because you need to remember the value
that you chose when you were in play
mode and that takes us right into our
challenge and our challenge or your
challenge is to adjust your jumping so
tune the gravity and jump speed to make
the jumping mechanic to your taste
and base your tuning on how many tiles
you want your player to be able to jump
so you can either make it two tiles
three tiles you can make him the best
and highest jumper in the entire world
it solely depends on your preference and
how you want to make your game feel so
pause the video right now and go ahead
and do the challenge
okay welcome back i hope that wasn't too
hard i hope you enjoyed that type of
challenge
so let's click on play and see what our
player does so
we move left and right and we jump and
that jump is a bit
too
nausea i think so let's make this
gravity 100 and now it's a bit more
snappy
and in order to help our player jump
higher let's click on player go to its
inspector and let's make the jump speed
i think 50. so let's see 15. now our
player jumps and you can see that he
actually disappears below the platform
which is not good and we faced this
problem before as you can remember from
i think it was when we added the run
speed to him
so we need to fix that before we
continue
i don't know if you face this kind of
problem while doing the challenge i hope
you didn't and it's not very hard
actually if we go into our players rigid
body you can see right here that we have
something called collision detection and
it's currently on discrete and if we
click on the list we can see that we
have another option which is continuous
and this is what we're going to choose
for our player now what what does that
mean well discrete is it checks for
collisions every
certain amount of time while continuous
is as it says it's continuously checking
for collision every
i think micro second or
millisecond i'm not sure but discrete is
for example every one or two seconds it
checks for a collision
and the continuous checks constantly
constantly for collisions now why do we
have the discrete option because we
might not have a body that it's very
fast or for example a slow moving
bird or something that will not need a
continuous collision with things around
it but if we have something like our
player for example right here that has a
gravity that is 100
he falls right through our
world so we'll make it continuous
continuous is a bit more uh
heavy on the processor of unity but it's
okay we can handle that i'm sure so
click on apply
go back into projects let's make this
let's make this gravity 200 because
i think we'll need it to be 200 let's
make the jump speed 50.
save that go back into play mode and see
if
that feels nice
it does feel nice so
let's see
i think it might need
the snappiness to the ground i think the
gravity is perfect
let's see if we want to make i think
that's enough i think 50 for a jump
speed is perfect so
i hope you tuned it to your preference
you don't have to make it just like me
you can have it whatever you want it's
your game it's your preferences and i'll
see you in the next video
tony robbins once said if you want to be
successful find someone who has achieved
the results you want copy what they do
and you will achieve the same results i
would love to teach you all about game
development and the best way to learn
anything is by doing it in a fun way
using unity's engine 2d we are going to
build our 2d platformer my name is
michael moore founder of double m game
dev and my goal is to make you the best
game developer in the most fun way
possible i've developed a strategy that
has helped thousands of aspiring game
developers achieve their goals of
creating real world games and i want to
do the same for you what i've learned is
that it can be very difficult to know
where to start and what steps to take to
go from beginner to intermediate to
professional not only in game
development but in programming and
learning how to code and i can say with
absolute confidence this course makes it
easy for any beginner with zero coding
experience to jump in and start learning
how to create incredible games and the
most amazing part is is that we're doing
all of this with the latest version of
unity with the newest techniques and
content in modern game development i've
helped thousands of people create real
world games and i want you to be one of
those people so how are we going to do
this first we are going to build the
foundation by learning the fundamental
aspects of c sharp programming we'll
understand what variables are how to do
if statements and create our own methods
and functions enabling us to make
incredible gains and while you're
building confidence in those areas we
are going to be playing in unity's
engine you'll understand how the
interface works how you can easily add
game objects and get comfortable with
everything available to you in unity and
the third component and most important
one is the game design side of things
where we'll talk about player experience
and create something enjoyable for
anyone looking to play your game we'll
then move on to more advanced sharp that
will enable us to control our game and
everything in it in a much better way
while still keeping our code readable
and very easy to understand we'll then
delve deeper into unity's tools that
will allow you to enhance your players
experience enhance your learning and
expand the horizon of the games that you
can make
and will create a synergy between
c-sharp programming unity's engine and
game design and from it build an
incredible and fun game so what should
you expect by the end of this course
you'll become a master problem solver
you'll understand the fundamentals of
coding and learn how to program games
just like the ones you're seeing on the
screen right now
you'll also have the chance to flex your
game developer muscles because with
every video there is a mini challenge
for you to complete and even if you
can't figure out how to do the challenge
don't worry i will be there to help you
after you tried and complete the
challenge with you everything in our
game will be configurable so you can
tweak play around and give the game an
individual and special feel about it so
you will be putting your own creativity
into it and really making it your own
i'm so excited to get started and hope
you are too this is the perfect time to
start learning how to code so dive in
with me and i will help you along every
single step of your game development
journey
you
UNLOCK MORE
Sign up free to access premium features
INTERACTIVE VIEWER
Watch the video with synced subtitles, adjustable overlay, and full playback control.
AI SUMMARY
Get an instant AI-generated summary of the video content, key points, and takeaways.
TRANSLATE
Translate the transcript to 100+ languages with one click. Download in any format.
MIND MAP
Visualize the transcript as an interactive mind map. Understand structure at a glance.
CHAT WITH TRANSCRIPT
Ask questions about the video content. Get answers powered by AI directly from the transcript.
GET MORE FROM YOUR TRANSCRIPTS
Sign up for free and unlock interactive viewer, AI summaries, translations, mind maps, and more. No credit card required.