Transcripts
1. Unity Game Development : Beginner to Pro course Outline: My friends, my name
is Roan Masud. Welcome you all to gaming
with Unity tutorial series. Let me take you through what
all topics are we going to cover in this particular
tutorial series. So we're going to start with Unity installation
and set up here. Furthermore, we are going
to proceed with creating first project and configuring
visual studio with Unity. This will cover creating a
C sharp script in Unity, understanding the structure
of a C sharp script, and finally printing Hello
world in Unity console. Furthermore, we are going
to proceed with data types, variables, and
operators in C Sharp, wherein we are going
to cover a operator, relational operator,
logical operator, and conditional operator. We're also going to study
control flow statements in CR, which will cover decision
making statements, switch statements, and
looping statements. We are also going to cover a
very important topic in R, which is collections in CR, which will include
list, sorted list, dictionary array, list
has table and stack. Later we are going to
understand UI in Unity, which will include Canvas, text, image buttons, Scroll View, Inputfield, slider,
and Anchor in Unity. Proceeding further, we are also going to learn
about Unity events, which will have event functions and your custom
functions as well. Then we'll have delegates in Unity which will
cover single cars, delegate, multicasts, delegate and delegate
events as well. Furthermore, we are going to understand Unity input system, which will have keyboard inputs, mouse inputs, and access inputs. Then we'll learn
about rigid body and collisions will be
introduced to rigid bodies. We'll have an example
of a rigid body. Create a floor in a game
and move a sphere using a rigid body or a rigid
body attached to a sphere. Again, in collisions will be introduced to colliders
and collision. We'll have Example 1.2 to understand colliders
and collision. Furthermore, we are going
to introduce to animation. Then we'll have animating
a sprite part one, part two, part three,
and part four. Later we'll understand or learn to animate a three D character. We'll have part one, part two, and part three for the same. Finally, to conclude the series, we are going to create a game called Knock the Cans in Unity, wherein we are going
to knock the cans down using a spear or
a ball game object. All right guys, this was a
brief overview for the series. Let's begin with installation of Unity in the next session. Thank you so much, guys. I will see you in the next
session. Thank you so much.
2. Introduction to Unity & instatllation: Good evening guys. My name
is Rohan S. This is session two in which I'm going to tell you about Unity game engine, and how to install Unity. So what is Unity? Before we start,
Let's know Unity is a cross platform
game engine which is used to create
2d3d VR and AR games. Okay, so it's a cross
platform game engine. It supports multiple
platforms such as Windows, Mac operating system,
Android and IOS. Why Unity? Okay, now there
are other platforms as well. There are other IDs as well
on which we can work on. But why Unity? Why Unity
is preferred so much? Why a lot of developers are
using Unity Statistics, say as of 2020, Unity made
applications were used basically by 2 billion
monthly active users, with 1.5 million
monthly creators. Okay, So 2 billion players were actually playing the
game made using Unity. Also, there were 1.5
million monthly creators. So among all the creators working on different
platforms to create games, 1.5 million monthly creators
used Unity as their ID, okay, as their game engine, to create any kind of game. Whether it could
be a two day game, it could be a three D game, it could be a VR game, it could be an AR game. Also, Unity Engine comes with a combination of
multiple assets. Now there are some
inbuilt assets. Also, you can download
assets from the asset store. How do I install Unity? Where do I get this Unity from? Is it freely available? Or what should I do if I
want to start with Unity? Okay, basically to
start with Unity, you have to simply go
to Unity download page. So there is a link
which I'm going to be dropping inside
this presentation, inside this session, okay? And you can go on this link
and follow the procedure, basically, this is the
link for that, okay? So it's ttpsstoverdtunity.com
slash download. So there is a button
which is going to be download Unity Hub. Before downloading Unity engine, you need to download Unity Hub. Click on Download
Unity Hub button. What is the next process? Okay? You open Unity
Hub and then you find a tab inside the Unity
hub which is install Tab. You click on the install,
you choose Installed. And then once you click
on the install tab, you will find an ad button in the install section
of the Unity hub. Okay? Click on the ad button and you will see
something like this. Okay, this is when you choose
installs in Unity Hub. Okay, over here I have
clicked on installs. And then you can see on the extreme right there is a button which is an ad button. You just need to click on that. And once you click
on the ad button, this is what is going to open. Okay? You just need to
select the version, what version of Unity
you want to download. And then you need to follow
the steps to install Unity editor or Unity Engine onto your laptop or your Dextop. That's it guys. Thank you so much for the session.
Thank you so much.
3. Create my first 3D project in Unity: Good evening guys. My
name is Rohan Vsdev, and in this session I'm
going to be teaching you how to create three D
project in Unity. Okay, so I have already
opened my Unity Hub. My version for Unity
hub is 2.4 0.5 Okay, so there is new version
available which is 3.2 0.0 but I'll be using for the demonstration
purpose version 2.4 0.5 So how to create
a project in Unity. Now in the last
session we saw how to install Unity Engine
and also Unity Hub. So I've already opened my
Unity hub to create a project. I just have to go here to
create a project which is new. Okay, I just have to click here. I have to select my version. For the purpose of
the demonstration, I'm going to be using Unity
version 2,019.3 Okay, I just have to click on this. Right now, I want to
create a three D project. Okay, Here I will have to put
the name for the project. Okay, I'll just
change the name here. First, Unity Demo. This is the name of my project. The location on which my project is getting
stored is D Drive. You can change the location if you want to store the project in drive or whatever location you want to
store your project. I just have to click
on this Create button. Okay, now this will
open your Unity Engine. This is the sample
scene that has been created when you create
a Unity project, rename the name of the senior will change the
name of the scene. Basically how to do that. Okay, just have to right click
here on the sample scene. Select Save Scene as from here. Okay, save this scene
into the scenes folder. Okay, so my first scene,
let's just save it. You all can see here the name of the scene
has been changed now. It's my first scene right now. Let's go into the scenes. And here is our scene,
my first scene. Okay, that's it guys. Thank you so much
for the session. See you in the next session.
4. Configure Visual Studio in Unity and get ready for scripting: Good evening friends. My
name is Rohan Asda and will be telling you how to configure visual
Studio with Unity. So what is Visual Studio? It is an integrated
development environment, which is IDE, which is developed by Microsoft, used to develop user interfaces, web applications,
mobile applications, and cloud based applications. Also, the code can be
written in C, Sharp, C plus plus, Visual, Basic, Python, and many
other languages. Altogether, Visual Studio
supports 32 languages. Visual Studio is
also available for both Windows and Mac
operating system. So there are three additions
for Microsoft Visual Studio, and they are as follows,
as we can see here. First one is the
Community Edition, which is a free version. Any individual
developer can basically develop free or paid
applications using that. The features are more or less similar to the
Professional Addition. Professional Addition is a
paid and commercial version. You need to pay if you want
to download or install. Basically, they provide
you with a free trial. But once a free trial is over, then you need to pay
for Professional, both for professional and
enterprise additions. What are the steps, basically, to install Visual
Studio in Unity? Okay, the first step
is to simply go on to Microsoft Visual
Studio download page. I have dropped in a link here. This is the link for that. Now, next, next to do, once you go on this link, once you go on this link, you will find a button which
is Download Visual Studio. You just have to
click on the button, which will take you
to another page. Okay, where you can
actually choose the version that which visual studio you
want to install or download. Once you click on
previous button, then that will take you to which is sttpsvisualtudiotmicrosoft.com
slash downloads. Okay, And this is how
the page will look like. This is Visual Studio 2022. There are other options as well. If you want, you can
download Visual Studio 2019. Also, once you come
here on this page, on the download page
for Visual Studio, okay, you need to click on the free download for
community version, because we are going to
use a free version here. We are not going to use professional or
enterprise versions because a paid version. So we're going to
click on button, which is free download. And once you click on this
button, what will happen next? It's very simple, will start
installing the installer. So the installer for visual studio basically
will get installed, which will be an EX file. So you just have to click on that EX file and start
the installation process. Once the installation
process gets started, you will see something like
this, this particular screen. And in this screen you
will see a work load stab. Here, you just have to
select a work load stab. Okay, in the work load stab, you have to check game
development with Unity here. Okay, this is very
important part while installing dual
studio for Unity. So you just have to check this. And then once this is
clicked or checked, you just have to click on the install button to proceed with the
installation process. Create a new project
using Unity Hub. Once the project is created, you will find edit option. Inside the Unity editor, you just have to click
on the Edit option and then you have to select
the Preferences option. So once you click on
the Preferences option, it will open a pop up window, which will be an external tool. Here, it will open
something like this. Okay? Now inside the
Preferences window, you will have to select
external tools here. Okay? So once you click
on the external tools, what you will have to do is for the external script editor, you will have to attach
version which you have just downloaded
which was studio 2019. So once this is
done from here on, what we need to do is
you need to go onto your Windows tab inside your Unity editor and
select Package Manager. Once you click on
that Package Manager in the window stab, you will see a screen like this and you will
have to type in Visual Studio co inside here in the search box or just
by typing visual, you will find package will be named by Visual
studio code editor. You just have to check on it. And then once this
process is done, you're free to actually use Visual Studio or C Sharp
inside your Unity editor. Thank you guys for the session. I'll see you in
the next session. Thank you so much guys.
5. Create my first C# script in Unity: Good evening guys.
My name is Roan. Are in the last session, we all saw how we installed
Visual Studio into Unity. Now in this session, I am going to be telling
you how to actually create a C sharp
script inside Unity. Firstly, we have an
Assets folder here. You can click on
the Assets folder and choose the Assets folder. Now to keep everything organized and keep all the scripts
inside one folder, what we are going to do
here is we are going to create a folder
inside this folder. Okay, We have to write click here and then
click on Create. Then you need to choose
folder option here. We don't want it
to be new folder, so we will just
rename it as scripts. Okay, Now let's open
the scripts folder. Okay? Double click on
the scripts folder. How to create a script. Now, inside the scripts
folder, it's very simple. Just have to write, Click here with your mouse
and then go to Create. Again, last time when
we created a folder, we chose folder option. Okay. But this time we're
going to create a script. We have to sharp script. Just click on the C
sharp script, okay. Now you need to rename it. By default, the name of the script will be
new behavior script, but we don't want it that way because we want
to rename the script. Now let's rename it
as my first script. Okay, your script
is created now. Now let's just click on
the script to open it. That's a Guys, see you
in the next session. Thank you so much guys.
6. Understanding the flow & structure of a C# script - Part 1: Good evening guys. My
name is Rohan Dev. In the previous session, we saw how to create a C
sharp script in Unity. As we all can see here, this class in Unity is
blueprint for your object. Now, all the scripts in Unity will always start with
a class declaration. And this class is
automatically created when you create a C sharp
script inside Unity. The name of the class
as we all can see here, my first script will be always same as the
name of your script. When we created a
script last time, the name of the script that
we kept was my first script, so will be the
name of the class, so it will always be same. What is system dot collection? System dot collections, or
Generic And Unity Engine, Basically these
are all namespace, which is a collection
of classes. Unity, the monobehavior
class here, including all other
core Unity features, are in Unity engine namespace. Okay, so Unity Engine
basically will have all the Unity core features and monobehavior class as well. Generally, when you
create a script, there are five important
aspects in the script. So what are these aspects? Firstly, this public keyword, then comes your class. The fourth is the
name of the script, or the name of the class. Then comes the colon
and the mono behavior. Let's first understand
what is public here. For instance, suppose
there are two scripts. And you want one script to
interact with another script. By making anything public means it is accessible
by another script. Also, this particular
class will be accessible by other class or by another Unity script as well. Now we all can see
mono behavior here. What is mono behavior? Mono behavior is a base class for all the scripts, basically. And this colon means
it inherits from, it simply means, okay, all the scripts
that we create in Unity C Sharp are inherited
from monobehavior class. Here in the next session, I'll be telling you what
are these functions, which is void start
and void update here. Okay, these are
also automatically created when we create
a Unity C sharp script. Thank you for the session. I'll see you in
the next session. Thank you so much.
7. Understanding the flow & structure of a C# script - Part 2: Hi guys, My name
is Rohan Vasudev. In this session we
are going to see what is void start and void update. Let's see what is void first. Void is the return
type, so in this case, the start function here created, it's not returning anything. Start function is
basically called once the frame of the
scene is created. One frame is just
one still image. All these images together
in rapid succession, will create a motion
for the game. Start is called once
the first frame of the game is created. It is only executed if
the script is enabled. If the script is not enabled. If it is disabled and the start function won't
get executed at all. It is also called once in life
cycle of the shaft script. So there is a life cycle for Unity script start function will be called only once
in the life cycle. What is start function used for? Start function is
used for initializing object properties or variable. Any variable you want
to initialize or any object property you
want to initialize, you can always initialize
inside the start function. Let's talk about
update function here. Again, we have
void here which is a return type for
the update function. So this update function is
not going to return anything. Update function is called only after the start
function has executed. Update function runs every
frame of the game or the seen. Okay? So it will be
called every frame execution of the update function depends on the frame
rate of the game. Frame rate simply means that how many frames
are generally created or called every
60 seconds or so? Generally, what happens here is the higher the frame
rate of the game, the time interval between the update function will
be low update function, the calling of an update
function to completely depends on the frame
rate of your game. That's it guys. Thank
you for the session. I will see you in
the next session.
8. Write first code in C# & print 'Hello Code": Hi guys, My name is Rohan Vasudev and in this
session I'm going to tell you how to print Hello
code inside Unity console. So to begin with, we will have to create
an empty game object. Everything in Unity is
basically a game object. So in this case, we will have to create an empty
game object here. So how do we create an
empty game object here? Okay, so for that purpose, just right click on your scene, which is my first scene. Choose game object here, and choose Create Empty. So this way we will create
an empty game object. The name of the
empty game object by default will be game object. We will just rename it
my first game object. We will attach the script, which is my first script here, which we created in
the previous sessions, to this game object. We don't need an
update function here. Let's just remove this
function because we are going to write our code
inside the start function. Let's start with
writing a code here. I'm going to use
debug log function in Unity to print hello code. This ends with a semicler. Debug dot log basically is a function inside Unity
in which you will have to pass a
string here and this will print hello code
inside the Unity console. Let's just save the script. Just click on my
first game object and choose console here. Just click on Add Component, button here and add the script
to this empty game object. Okay, click on Add Component
and type in my first. In the search, you
will find the script. Click on my first
script and the script is attached to your
empty game object. In our case, it is my
first game object. Okay, now save the scene and run by clicking on
this play button here. And here we have printed Hello
code inside Unity console. That's it guys. Thank you
so much for the session. I will see you in the next
session. Thank you so much.
9. Understanding data-types & variables in Unity C#: Hi friends, my name is Rohan. Sure. And in this session
I'm going to explain you data types and variables
in C Sharp and Unity. A data type specifies
the type of data. This data could be a string, or an integer, or a bullion, or a float, or double. Again, depending on the accepted
value or the data type, various operations
can be performed on that particular data string. Data type is used to store
sequence of characters, numbers, characters in the
form of words or sentences. A value of a string data type is enclosed within double codes. It is always put
inside double codes. The another data type
is your data type, which is used to store
32 bit integer numbers. The numbers are generally
whole numbers which will include positive and
negative numbers as well. Again, we have a
float data type, which is used to store
floating point numbers, is also used to store
floating point numbers. But the only difference between a float
and double is that double stores larger size
numbers than the float. Again, we have a whole
datatype which is generally used to store true
or false values, generally used to
store information. This information could
be a name of the player, or a score, or a hell. Now, value assigned to a
variable can always be altered, modified during the
execution of a program. Again, when a
variable is created, some space in memory
is allocated. Declaration of a variable
always starts with a data type followed by
the name of the variable. Here is my editor. We have already created
an empty game object. I have renamed that
empty game object to variables object. Again, I have created a script. Here, the name of the
script is my variables. Let's open the
script and declare some variables
inside the script. Firstly, let's declare
a string variable. Okay? First name equals to, let's assign a value
to the variable. Okay, Danny, in
declaration of a variable, string is the data type, first name is the
name of the variable, and Danny is the value assigned to the variable, first name. Okay. Now let's declare a
variable with data type. Okay, Let's name
it as number one. Let's assign a value. Let's declare a variable
with float data type. Let's name it as number two. And let's assign a
value 10.5 Now let's declare a variable with a data type double
number three equals to. Lastly, let's declare
a variable with a bull data type val. My val is the name
of the variable. Let's assign the value true to the variable variables that
we have declared here. We are going to print those
variables inside the console. Let's start printing the
values for the variables. Okay, we just need to pass the name for the variable here. Let's save the script, and let's attach this script to the game object which
we have created here, which is variables object. Okay, here it is.
So that's it guys. Thank you for the
session. I will see you in the next session.
Thank you so much.
10. Introduction to the Operators in Unity C#: Hi guys. My name is Rohan
Vasudev and in this session I'm going to explain to you
what are operators in Unity. Sharp operators are
special simples or a character that perform
some actions on operands or variables basically
represents an action or a process that we do
on variables or operands. Operators are foundation for
any programming language. Now without the
existence of operators, any programming language would
basically be incomplete. Now what are types of operators? How many types of operators
are there in Unity? Sharp? Let's see. First is your
arithmetic operators. Then we have
relational operators, then we have logical operators, then we have
assignment operators and conditional operators. Let's first see what are
arithmetic operators? What are arithmetic operators? Arithmetic operators are
generally used to perform mathematical operations
on variables or operands. Now, there are some types
of arithmetic operators. The first is your
addition operator. Addition operator is used to compute additions of two
operands or variables. With this operator, we can basically add two
operands or variables. It can also be used for concatenation of two
string variables. Example, if we have an int a equals to five and int B
set to the value of ten, then the output for the
addition would be 15. It basically computes
a basic addition of two variables or operands. Next is your
subtraction operator. Subtraction operator
is used to subtract right hand operand from
left hand operand again. The third is your
multiplication operator, where we actually compute multiplication of
operands or variables. We have division
operator which divides your left hand operand by
its right hand operand. Again, is your modulus
operator which returns remainder when left hand operand is divided by right
hand operand. So if you perform division, then the remainder which you get would be your output
inside the console. Now let's get into the Unity
editor and let's see how we actually perform some actions
using arithmetic operators.
11. Understanding Arithmetic Operators & it's usage: Guys, we are into Unity Editor. Now as you all can see, I've already created
an empty game object which is operators object. And again, I've created a C sharp script which
is arithmetic operators. Now to perform some
actions or calculation, let's open the script
which we have created, which is arithmetic operators
in A equals to five, in B equals to ten. Okay, bug dot log A plus, this is your addition operator. This is a commented code. Basically, it's not
going to run debug log. Okay, let's subtract a from B inus debug log d here, here is the output. Let's continue the
topic operators in the next session.
Thank you so much.
12. Understanding Relational Operators & it's usage: Hi friends. My name
is Rohan Vase. In the last session, we
saw arithmetic operators. In this session, we are going to learn about
relational operators. What are relational operators? Relational operators
are used to compare two values or
variables, or operan. Now, what are the types
of relational operators? The first relational operator
is equal to equal to operator is used to check whether two values
are equal or not. If both the values are equal, then it returns true. Or if they are not equal, then it returns false. For example, if we
have two variables in A equals to five and
in b equals to five, then the result will be bool. We are storing the value in
a variable called result. Okay? We are checking here if both variables have the same values and
how we are doing that. We are doing that using
equal to operator, okay? In this case, five
is equal to five, the output will be true now. Next is your not equal
to operator, okay? Not equal to operator is used to check whether two values
are equal or not. Now, if both the
values are not equal, then it returns two, else it falls, then we have
greater than operator. Greater than operator is
basically used to check if the left hand operand is greater than the
right hand operand. For instance, if we have
a variable a whose value is set to 50 and a variable
whose value is set to ten. Then the bol result
for a greater than in this case will be two because
50 is greater than ten. Now let's move on to
the next operator, which is less than operator. Less than operator is
basically used to check if the left hand operand is lesser than the
right hand up brand. In this case, we have set the value of A to 50
and a value of 210. A lesser than is obviously
falls because 50 is not lesser than the output for this particular
example will be falls. Again, we have greater
than equal to, greater than equal to
operator is used to check if the left hand oprand is greater than or equal to
right hand brand. It will check for both
the conditions whether it is greater than or equal
to the right hand operand. The last relational operator
will be or lesser than, equal to, less than equal to. Operator is used to check if the left hand up brand is lesser than or equal to the
right hand brand. In this example, we are checking here the value of A
which is set to ten, and the value of which
is set to ten again. Okay, we are checking here if a is lesser than or equal to b, but in this case a is not
lesser than it is equal to, it is obviously going to bring
the output as true here. Now let's get into the editor and let's
write a piece of code, and let's print the
values in the editor. Okay guys, so I am in
the Unity editor now, and I have already created
an operator's object here. This is an empty game object. And also I have created
a C sharp script, which is a relational
operators script. I have named the script as
relational operators and attach the script to the
operator's object Here. Let's open the script
and let's see the code. Okay, so we have already
written a code here. We have declared a variable
which is in a equals to five and a variable
of data type inc, and the value of
variable is set to ten. And we have declared a bool
variable here, result. And we have not set any value
here for the bool variable. Now inside the start
function, firstly, we are checking whether
a equals to equals to b. Then the value of
the result will be assigned to the
bull variable here. Because the output for
this will be a Bo output, we are assigning that output to the bool variable result here. Lastly, we are checking if a is lesser than or
equal to B or not, and the value is assigned to
the result variable here. Now let's just run this code and let's see the
output for the core. That's it guys, let's continue the operators in
the next session. I will see you in the next
session. Thank you so much.
13. Understanding Logical Operators & it's usage: Hi friends, My name is Rohan
V. In the last session, we learned about
relational operators. In this session, we are going to learn about logical operators. What are logical operators? Logical operators
are used to combine two or more conditions or relational statements and
returns pullion value. Logical operator will
always pull value. What are the types of
logical operators? First is your logical operator. Logical operator will check if all the conditions
are true or not. It only returns true if all
the conditions are true, and it returns false
if either one of the relational statement
or condition is false. Next, move on to the
next logical operator, which is your logical operator. Logical or operator
checks if at least one of the condition is true
or not returns true. If one or all the relational statements
or conditions are true and returns falls only when
all the conditions are false. Then lastly, we have
logical operator. Logical operator returns true if the condition
is not satisfied. Now let's get into the Unity editor and
write a piece of code. Okay guys, I'm in the
Unity editor now, so I have already created
operator's object here, which is an empty game object. Then I've already created
a script here which is logical operators
script and already attached the script to
the operator's object. Let's open the script
and see the core here. Guys, we have already declared
a bull variable x here, whose value is set to be true. We have already declared a bull variable y whose value
is set to false. We have already declared
again a bull variable result. And we have not assigned any
value to the result yet. Okay? Now inside
the start function, this and operator
here will check if both the variables variable
x and y are true or not. But in this case
variable x is true, that variable y is false. Hence, the output
here will be falls. The output is then assigned to the pool variable result here, and is then printed
in the console. The R operator here will
check if at least one of the value for the variables
x and y are true or not. In this case, the value
for variable x is true, hence the output
here will be true. The output is then
again assigned to the bull variable result and is printed in
the console here. Okay, Now we have already seen the result for
the operator is false, but we are using a
knot operator here. The knot operator returns true
if the condition is false, hence the output here
will be true, This value, This output is then assigned again to the variable
result here, and is then lastly printed in the console using bug
dot log function. Now let's run this code, and let's see the output inside the unity console.
Let's run the code. Okay, that's it. And operator
is giving me an output of false or Operator
here is giving me an output of true and
not operator here. Lastly, is giving me
an output of true. So that's it guys. That's
it for the session. I will see you in
the next session. We'll continue on the topic operators in
the next session. Thank you so much guys.
14. Understanding Conditional Operators & it's usage: My friends, my name
is Rohan Masdev. In the last session, we
saw logical operators. In this session, we are going to learn about
conditional operators. What are conditional operators? Conditional operators
has three operands. The syntax for conditional
operators is as follows. The first will be
your condition. Then there is a
first expression, and then comes a
second expression. Now, since this conditional
operator has three operands, it is also called as
a ternary operator. Generally, how it
works is, firstly, it evaluates the condition here. Now, if the condition is true, the first expression is evaluated
and becomes the output. And if the condition is false, the second expression is evaluated and
becomes the output. Let's get into the Unity editor and let's write a piece of code. Okay guys, we are
into Unity Editor. Now, I've already created
an empty game object, which is operator's object. And I've already created a script which is
conditional operator. Let's open the script, and let's see the code here. Now we have already declared a variable a which
is of data type int, and the value is set to five. We have also declared
variable of data type end, and the value is set to ten. We have also declared a
bull variable result, and we have not assigned
any value to it initially. Now inside the start function, we are checking if
a is greater than. Basically, we have applied a
condition here to check if a is greater than if
the condition is true. Then the first expression
which is true here, which is a bool true here, will be assigned to
the variable result. If the condition is false, then the second expression
which is false here, be assigned to the
variable result here. The output will
then be printed in the unity console using
debug dot log function. Similarly, over here we are checking if a is lesser than B, the value of a is lesser than B. And if the condition is true, then the first expression
which is true will be, will be assigned to
the variable result. And if the condition is false, then the second
expression which is false will be assigned to
the variable result here and will be printed in the Unity console using
debug dot log function. Let's run the code
in the editor, and let's just see
the output for the code, here it is guys. The output for the code, a greater than is false, a smaller than B is true. That's it guys. Thank
you for the session. I will see you in the next
session. Thank you so much.
15. Introduction to Control flow statement in Unity C#: Hi friends. My
name is Rohan Dev, and in this session we
are going to learn about control flow statements
in Unity, C Sharp. What are control flow
statements in C Sharp? Control flow statements are
the statements that alter or change or modify the flow
of a program or the code. It provides better control on the flow of execution of a code. More complex
programs can also be written using control
flow statements. Now the program is executed from top to bottom in
the order it's written. Control flow
statements can modify the flow of the
execution of a program. The code which is executed
from top to bottom can be modified using
control flow statements. Thank you for the session. I will see you in the next
session. Thank you so much.
16. Understanding if-statements in Unity C#: Hi friends. My name is Rohan
Dev, and in this session, we are going to learn about Controlled Flow
statements in Unity shop. Now, what are the types of
control flow statements? The first is your decision
making statements. We have switch statements, and then we have
looping statements. What are decision
making statements? Decision making statements is similar to that of
making decisions. In your real life, it will execute certain
block of code if the condition is true
or is satisfied. The if statement checks
for the condition. If the condition is true, then the block of
code is executed, otherwise it is not executed. Let's get into the
Unity editor and let's write a piece of
code for an if statement. Guys, we've already declared a variable player health here, which is of data type end, and the value is set to 30. Inside the start function
there is an F condition, and we are checking whether player health is
lesser than 50 or not. If the players health
is lesser than 50, then we are going to
print in the console, Players health is to look. So we have our output here
inside the Unity console. Thank you for the session. I will see you in the next
session. Thank you so much.
17. Understanding if-else statements in Unity C#: Hi friends, My name is Rohan
Dev and in this session we are going to learn about control flow statements in
Unity. C sharp. If statements checks
for the condition. And if the condition is true, then the block of
code inside the if statement is executed. But what if the
condition is false? In that case, the code inside the L statement
will be executed. The L statement tells the core what to do if
the condition is false. Again, we have declared a
variable of data type int, which is player health, and the value is set to 70. Inside the start function, we are checking if
the players health, the value of player health
is lesser than 50 or not. If the condition is true, then we are going to print players health is too low
inside the Unity console. And if the condition
here is false, then Players health is good will be printed inside
the Unity console. Guys, here it is.
Here is the output, Players health is good. Thank you for the session. I will see you in the next
session. Thank you so much.
18. Understanding if-else-if ladder statements in Unity C#: Hi friends. My name is Rohan
Dev and in this session we are going to learn about control flow statements
in Unity C sharp. If ladder statement checks
for each if condition, all the statements are
checked from top to bottom. First condition will
be checked first, then the second condition
will be checked, then it moves on to the third
and so on and so forth. The code inside the
if statement is executed which
evaluates to be true. Only the code or
the block of code inside the if L statement
will be executed, which will be true. If none of the if
conditions are true, then the last L's block
will be executed here. Now the player health is
set to the value of 50. Inside the start function, we have an if condition. Inside the if condition, we are checking where the player's health is
greater than equal to 80 and player health is smaller than or lesser
than equal to 200. And if the condition is true, then we are going to print
players health is super. If the condition is falls here, then it moves on to
the L statement here. Now again, it checks for
player health greater than equal to 60 and player health is smaller
than equal to 79. Now if the condition
is true here, then this block of
code will be executed. Otherwise, if it is false, then it moves on to
the next statement, which is player health
greater than equal to 40 and player health
lesser than equal to 59. Again, if the condition
is true here, then the block of
code will be executed and players health is not good will be printed in
the Unity console. If the condition is false here, then it moves on to
the L statement. And finally, if all the
conditions falls here. Then lastly, code
inside the L statement, players health is
in a bad state, will be printed in
the Unity console. Now let's run the code
and see the output. In the Unity console, players, health is not good,
so here it is. Here is the output. Thank you for the session. I will see you in the next
session. Thank you so much.
19. Understanding switch-case statements in Unity C#: Friends, my name is Rohan Dev. In the last session, we spoke about decision
making statements. In this session, we are going to talk about switch statements. What are switch statements? Switch statements
are an alternative for FLSA ladder statements. Switch case statement is
a selection statement. Here is the syntax for a switch case statement
wherein we have a switch keyword and then we have to put the expression
inside the bracket, and then we have cases. Now the block of
code or statement is executed if the expression matches with one of the
case or expression value. Again, we have a
break keyword here. Now this break statement
is used to move out of the switch once the expression matches with one of the cases, Once the value for
the expression matches with the
value for the case, then the break statement is
used and the switch is ended. The switch will continue
to check for all the cases until the break statement is
found or the switch ends. Now lastly, if none of the case matches
with the expression, then the last default
is executed and the block of code inside the default case is
printed or executed. Again, the switch is ended using the break statement
in the default case. Now let's get into the Unity editor and let's
write a piece of code. Now guys, we are here
into Unity editor. We have created an
empty game object. We have also created
a shaft script. And the name of the
script is Switch Case. Let's open the
Switch Case script. And let's have a look
at the code side. The script, we have already
declared a variable, player's health, and
the value is set to 20. Inside the start function, we have already declared
switch case players health. Here is an expression case ten will check if the value of plays health is
equal to ten or not. If the value of plays
health is equal to ten, then the block of core which
is case ten is executed, will be printed in
the Unity console and the break statement
will end switch. If the value does not
match with the expression, then it will move
on to the case 20. Case 20 will check if the value of flares health is
equal to 20 or not. If the value of flares
health is equal to 20, then the block of core which
is case 20 is executed, will be printed in
the Unity console and the break statement
will end the switch. If the value of players, he is not equal to 20, then it will move on
to the default case. And the default case is executed will be printed
in the Unity console. Lastly, the break statement
will end the switch here. Here is the output
case, 20 is executed. Thank you so much
for the session. I will see you in
the next session. Thank you so much guys.
20. Understanding loops in Unity C#: Hi friends, My
name is Rohan Vdv. In the last session we
saw switch statements. In this session, we
are going to learn about loop control segments. So, what are loop
control statements? Okay. Generally, loop control
segments are used when you want a statement
or a block of code to be executed multiple times. Again, depending on the
conditions to be evaluated. The condition to be evaluated needs to be true for
the executions of the statements or
block of code inside the look so the condition
has to be true if you want these statements inside the loops to be executed
multiple times. What are the types
of loops we have? Here we have y loop, for loop, and to y loop. Let's have a look at a Y loop. What is a Y loop? Okay, the condition is applied at the beginning
of the loop loop. Variable initialization is done before and outside the loop. So the variable which
you're going to initialize, it's going to be outside the loop and not
inside the loop. Now, the block of code
inside the loop will be executed till the
condition is true. And once the condition
becomes false, then the loop will be
exited or terminated. Here is the syntax
for a wide loop. First is your loop
variable initialization. This is where you initialize the variable which is
outside the Y loop. Then we have a Y loop, and then we have a condition inside the brackets
for a wide loop. Now inside the Y loop we have a block of code to be executed, and once the block
of core is executed, we do increment or decrement
of a loop variable. Let's get into the
Unity editor and let's write a piece of code
to execute a loop. Okay guys, I'm here
in the Unity editor. I've already created
an empty game object, which is control flow object. And I've already created
a C Sharp script. I've named the script as y loop. Also, I have already attached a script loop to the
empty game object. Let's open the script here. Okay, inside the script, we have already declared a variable health
of data type int, and the value is set to five. Inside the start function, we have also declared a
loop in which we have a condition where
we are checking whether value of health
is greater than zero. Inside the y loop, we are printing the
value of health, and once the value of
health is printed, we are decrementing the
value of health by one. The loop will run
here till the value of health becomes one. Once the value of
health is zero, the loop will be
exited or terminated. Let's run the script. And let's see the output here. Okay, so here is the output. Player health is five, players health is four, players health is three, players health is two, and players health is one. Once we get the value
of health to one, the loop is exited. The loop is terminated here. Now let's go and understand
what is four loops. So what is four loop? Four loop is similar to that of y loop with a
difference in tax, initialization of
a loop variable. Testing of a condition
increment and decrement of a loop variable
are in one single line. Here, the block of code inside the loop will be executed again till the condition is two. And once the condition
becomes false, then the loop will be exited
inside the for loop script. Inside the start function, we have a four loop declared
inside the brackets. For the four loop, we
have already initialized a variable whose
value is set to one. Then we have a condition
in which we are checking whether value of I is
smaller than five. Then again, the
value of I is being incremented by one
on every iteration. Inside the loop, we are
executing a statement. In this case, we are just
printing the value of in the Unity console using
debug dot lock function. Let's run the code. Let's see the output
here. That's it guys. Here is the output for loop. Play scores one, scores two. Play scores three, and
plays four is four. Once the value of score is five, the loop is exited
or terminated here. Okay, so what is a y loop? Okay, y loop is similar
to y loop except that it checks the condition only after the statements
are executed, executes the statements at least once before it checks
for the condition. Now inside the script, we have already
declared a variable, coins whose value is set to one. Inside the start function, we have declared a loop. Inside the block, we are printing the value
for the coins. Once the value of coins is
printed in the unity console, the value of coins is
incremented by one. The Y loop will check
for the condition here whether the value of coins
is lesser than zero. If the condition is true, it will again get into the two block and the block
of code will be executed. If the condition is false, the loop here will be
exited or terminated. Let's run the code
and let's have a look at the output
in the Unity console. For this, here is the output
guys number of coins, one. Since the condition was false, the loop is exited here. That's it guys. I will see
you in the next session. Thank you so much guys.
21. Introduction to Collections in Unity C#: Friends. My name
is Ro and Sudev. In this session, we are
going to talk about collections in Unity C.
What are collections? Collections are
specialized classes that store series of values, or objects, or elements. With the help of collections, we can perform
various operations. What are these
operations that we can perform With the help
of collections classes? We can store data, our values, we can update data, our values, we can delete data, our values, we can retrieve them, and we can also sort them. What are the types
of collections? Collections are
basically categorized into two collection classes, and they are as follows, generic collections and
non generic collections. What are generic collections? Generic collections
are defined in system Do collections
dot generic space. Whenever we want to use
generic collections, we have to use the
name space system. Do collections generic defined by set of interfaces
and classes. Interface is a
blueprint of a generic. Collections handles data
in a type safe manner and it eliminates
the type mispatch. What is the type safe? Type Safe here simply means that one data type cannot be
assigned to another data type. Here are some generic
collection classes. First is your list contains
data of a specified type. List grows automatically upon adding data or elements to it. Short list sorted list always stores data in key
and value pairs. The data that will
be stored inside the sorted list will always
be in a key value pairs. The elements are added in the ascending order
of key dictionary. Dictionary stores data in
key value pairs again, but the elements that
are added to it won't be in the ascending order of
the key Q. What is a Q? Values are stored in first
in and first out manner. What is first in
first out manner? It simply means that
the elements that are added first will be
first to be retrieved. It has Q method to add values to the Q and DQ method to
retrieve the values. When you use Q method, it not only retrieve the values, but it also removes
the values from the what is non
generic collections. Nongeneric collections
is defined in system dot
collections namespace. When we want to use non
generic collections, we have to specify system dot collections as a
namespace inside the script. It can handle any
type of object, but the data is not handled
in a type safe manner. Here, this is the
difference between a generic collection and
non generic collection. Generic collections
basically handles data in a type safe manner. Non generic collections does not handle data in a
type safe manner. Here are some non generic
collection classes. First is your Arraylist. All stores objects
of any data type, grows automatically upon
adding the element. Then we have hash table. Hash table stores data
again in key value pairs, values can be retrieved by
hash values of the keys. Then we have stack stores the values in last in
and first out manner, which is your Lifo manner. What is Lifo manner? Lifo manner simply means
that the data to be added last will be the
first data to be retrieved. Push method is used again
to store a value here and pop and peak methods
are used to retrieve the value stored
inside the stack. That's it for this session.
In the next session, we are going to have a look at some generic
collection classes. We're going to have
a look at a list, how to create a list
inside Unity. C sharp. Thank you guys. I
will see you in the next session.
Thank you so much.
22. Understanding List & it's usage.: Hi friends, My name
is Rohan Vasudevn. In this session, we
are going to talk about list and how
do we create a list and some of the
important aspects of the list in Unity C sharp. So we have already created a list here and the name
of the list is play names. The list is of data
type string here, so all the values
that we can add to the list will be of
data type string here. Also, we have initialized
the list using a new keyword inside
the start function. For code one, we
are adding values Dan and Sam to the list using
add method for the list. The values Dan and Sam inside the list can be
accessed using index. Here, the index of a list
will always start from zero. For code two, we are printing value Dan which is at
zero index and value Sam, which is at the first index
in the list player names. For code three, again, we are removing the value at the zero index,
which is your Dan. When you remove the value
Dan from the zeroth index, the value will be replaced by the value at the first
index, which is Sam. In this case, Sam will
replace Dan here when we print value inside player
names at the zero at index. In this case, for
code number three, Sam will be printed in the Unity console using the
bug dot log function here. For code four, we are inserting a value
at the first index. We are inserting a value, Rachel at the first index using insert method here for the list. For code five, we are printing all the values from the
list using a four loop. We have already
declared a four loop. The value of I has been initialized with zero
player names dot count. Here is the number of elements inside the list player names and I has been incremented here
by one on every iteration. We are then printing
the value Sam here, which is at the zeroth index
on the first iteration. And on the second iteration, we are then printing the value Rachel inside the Unity console. Once the value of I
becomes two here, the loop will be
exited and terminated. Let's get into the Unity
editor and let's see the output for the entire code
inside the Unity console. Okay, so here it is. Here is the output
printing values from the list using index. Okay? Dan initially was at 08 index and Sam
was at first index. So we are printing Dan
and Sam here printing values from the list after removing the value at 08 index. Since Dan has been
removed from the list, now Sam is on zeroth index now printing all the values from the list using
loop and index. Okay, so that's it guys. That's it for the list here. In the next session, again, we are going to continue with some generic classes collection. Thank you so much. I will
see you in the next session.
23. Understanding Sorted List & it's usage.: Hi friends. My name
is Roan Masudev. In the last session
we spoke about list. In this session, we are going
to talk about sorted list. Sorted list will have all the elements in
key and value pairs. The elements added
to the list will be in ascending order of the key. Now, in this script, we have already declared a
sorted list for code one. We are adding key and value
pairs to the sorted list. In our case, it is core
list using add method three is the key here and 100 is the value
for the key three. For code two, we are printing the values from the
sorted list using keys. If we put one inside
the brackets here, we will get the value
for that particular key. When we use bug dot
log function to print score list one
inside the bracket. Then the value 200 will be
printed inside the console. Again, score list three
inside the brackets will print 100 inside
the Unity console. Here for code three, we are creating a key here, two, and assigning the
value 150 to the key two. For code four, we are using a contents key method to check whether a particular
key exists or not. And if the key exists, then we are going
to print a value of that key in the Unity console. For code five, we are
printing all the key and values from the sorted
list using for each loop. For each loop basically will iterate for all the items, key, and values inside
the score list here, which is our sorted
list. Here it is. Here is the output
printing values from sorted list using keys. We printed the values
for the particular keys. Lastly, we printed all
the key and values from the sorted list
using for each loop. So here is the output for that, key is one and value is 200, key is two, value is 150, key is three, and value is 300. That's it. That's
it for the session. I will see you in the next
session. Thank you so much.
24. Understanding Dictionary & it's usage.: Hi friends. My name
is Rohan Masugev. In the last session we
spoke about shorter list. In this session we are going
to talk about dictionary. Dictionary stores key
value pairs, key insider, dictionary cannot be
null and must be unique. Now, value inside
a dictionary can be null and can
also be duplicated. In this script, we have already declared a
dictionary here. The data type for the
key is string here, and the data type for the
value will be string here. Player details is the name
of the dictionary here. And we have also initialized a dictionary using a new keyword inside the start function. For code one, we are adding key and values to
the dictionary name. Here is the key and Danny, here is the value
for the key name. Again, country here is the key, and USA here is the value
for the key country. Code two, we are printing the values in the dictionary
using their keys. For code three, we are
removing the key country here, using the remove method
for the dictionary. For code four, we are
printing all the keys and values from the dictionary
using for each loop. So let's get into
the Unity editor and let's run the code. And let's see the output here. Okay guys, so here
is the output for the code printing values from
the dictionary using key. So we have our output
as Danny and USA here. Once this is done, then we are removing the key
country from the code. And lastly, we are having an output as Key name and Value. Danny, there is no country
here because we have already removed the country
from the dictionary. That's it guys, Thank you
so much for the session. I will see you in
the next session.
25. Understanding ArrayList & it's usage.: Hi friends. My name
is Rohan Vasdev. In the last session
we spoke about Q. In this session we're going
to talk about an ery list. Ery list is an
ordered collection of elements of any data type. Eralst grows automatically upon adding the elements to it. Eryalist can also have
duplicate elements inside it. In this script, we
have already declared an Eryallist and the name of
the Aral list is my list. We have also initialized the Aral list using
a new keyword, and we are adding two elements, Dan and John, inside the list. Upon initialization inside the start
function in code one, we are printing all the values
from the R list using a. For each loop we have already declared a
for each loop here, which will iterate
over all the elements inside the array
list, my list inside. For each loop, we are printing all the elements using
rebug dot log function. So basically this will print Dan and John in
the Unity console. In code two, we are adding
more values to the array list, Sam and Tina, using add method for the array
list in code three. Again, after adding
the elements, we are printing all the
elements or values inside the array list again
using for each loop. Now in code four, we are removing a value
or the element from the Aral list at
the zeroth index using remove at function. Basically, on the
zero eth index, we have Dan here. So we are removing Dan
from the ery list. Now, after we remove
Dan from the ery list, we are inserting a new value on the zeroth index to the ery
list using insert method. Now in code six, we are printing all
the values from the ery list using for each
loop after removing and inserting the value at
the zeroth index guy. So here it is. Here is
the output printing all the values from the
realist using for each loop. Initially, we added Dan and John during the time of
initialization to the relist. We are printing
Dan and John here, printing all the values from the Alist using a for each loop. After adding more values to it, we added Sam and
Tina to the list. We have here Dan, John, Sam, and Tina. Now lastly, printing
all the values from the list using
a for each loop. After removing and inserting a value at the zero at index, we removed Dan which
was at the zero at index and we added Jenny
and zero at index. Here is the output for that. We have Jenny, John,
Sam, and Tina. So that's it guys. Thank you for the session. I will see you in the next
session. Thank you so much.
26. Understanding Hashtable & it's usage.: Hi friends. My
name is Rohan Dev. In the last session,
we spoke about a list. In this session, we are going
to talk about hash table. Hash table stores data or
elements in key value pairs. The values inside the
hash table can be retrieved using the
associated keys. The elements added to
the hash table can be of same data type or
different data type. Keys inside the hash
table cannot be null, but values inside the
hash table can be null. Hash table class implements dictionary collection,
innumerable interfaces. Now in this script, we have already declared a hash table and the name of the hash table is players data. We have initialized the
hash table here using a new key word inside
the start function. For code one, we are adding key value pairs to the hash
table using add method. Here, code two, we are printing a value
for a specific key. In this case we are printing the value for the key name here. Debug dot lock function
here will print and which is the value
for the key name here. For code three, we are using eye collection to retrieve all the keys from
the hash table. The keys are retrieved
by using dot keys. For code four, we are
printing all the keys and values from the hash table
here using a for each loop, we have already declared
a for each loophole here, which will iterate
basically through all the keys inside
the hash table. All keys is a variable
or an object in which all the keys are stored here using eye collection
in code three, when we are using a
debug lock function. Inside the for each loop. Here here will
print all the keys. The value for every key will be printed by using players data, which is your hash table, and putting a key inside it, which is, in this case 45. Here we are removing
a specific key. In this case, we are
basically removing a key city from the hash table by using remove method for
the hash table. For code six, we are printing all the
keys and values from the hash table using a for each loop after removal
of a specific key. So let's go to the
Unity editor now, and let's print the output. Okay guys, here it is. Here is the output
from the code printing a value for the key name
from the hash table. So the value for the key
name is and in our code. So we are printing, and here printing all the keys and
values from the hash table. So basically we are printing all the keys, key city value, New York, key name value, and key age value 18. So we are printing all
the keys and values here inside our hash table. Now lastly, we are printing
all the keys and values from the hash table
using a forage look after removal of a specific key. We removed it from the hash
table and hence we are printing key name value
and and key age value 18. So there is no city here
since we have removed it from the hash table using remove
function for a hash table. That's it guys. Thank
you for the session. I will see you in the next
session. Thank you so much.
27. Understanding Stack & it's usage.: Hi friends. My name
is Rohan Vasudeven. The last session we
spoke about has table. In this session we are
going to talk about stack. Stack is a special type
of collection which stores data or elements
in Lifo manner. Lifo here means lasting
and first out manner. The element to be
added last will be the first element to be
retrieved from the stack. Okay, so in this script, we have already declared a stack and the name of
the stack is my place. We have initialized
the stack using a new keyword inside
the start function. For code one, we
are adding values to the stack using
a push method. So, the push method is basically used to add values to the stack. So, we are adding Danny here, then we are adding Sam here. And lastly, we are adding, and here Andy is
the last element, or the last value to be
added here in code two, we are printing all the values inside a stack using
a for each loop, we have already declared
a for each loop. For that and inside
the for each loop, we are using debug
dot log function to print all the
values inside a stack. This for each loop basically
will print and first, because stack works
in a Lifo manner, last in and first out, and is the last element added. So it will print and first, then it will print Sam, and lastly it will print Danny. Here in code three, we are retrieving and printing the last value added to a
stack using peak method. Peak method returns the last
element inside the stack, but does not remove the element. It does not remove the value, so it will just retrieve
the value here. Okay, Now in code four, we are using a pop
method which will return the last value
added to the stack, but it will also remove the last value
added to the stack. Okay, So in code five, we are printing
all the values in a stack after using
the pop method. Now using a pop method. In code four, we have removed here value and from the stack. So, once we run
this for each loop, we are going to print Danny and Sam here in the Unity console, since Andy has been
retrieved and removed from the stack in the code four. Now let's get into
the Unity editor, and let's see the
output for this code. So here it is. Here
is the output, printing all the
values in a stack. So we are printing
And Sam and Danny, as I stated earlier. Okay, stack works
in a Lifo manner, so Andy was the last
element to be added first, so it will be the first
element to be retrieved. So, we have retrieved and here first then we are printing Sam, and lastly, we are
printing Danny here. Okay, retrieve and print a last value added to a
stack using peak method. So, again, here we are retrieving last element
added to the stack, last value added to the stack, which is Andy, and
we are printing it. Now, lastly, we are printing all the values in a stack
after using the pop method. So we used a pop method and
we removed the last element, retrieved and removed
the last element, and we printed all the remaining
values inside a stack. So that's it guys. That's it for the session. I will see you in the next
session. Thank you so much.
28. Introductions to UI in Unity & create a Canvas: Friends, my name is Rohan. As today we are going
to talk about Unity. Uy, Unity UI, in simple words, is used to design and create user interfaces for
games and applications. In this session, specifically, we are going to talk about one of the components
of Unity UI, which is your UI canvas. So what is canvas? Canvas is created as a game object with a canvas
component attached to it. So whenever you create
a canvas inside Unity, it is always created
as a game object which will have a canvas
component attached to it. Canvas is displayed as a
rectangle in the scene view. Every canvas will have a transform component
attached to it. All other UI elements should
be inside of a canvas. Canvas will be always
or should be apparent, of all other UI elements
or UI components. All the elements inside
the canvas are drawn in the order they appear
in the hierarchy. Now there are three render
modes for the canvas. First is your screen
space overlay, which places the UI elements on the screen rendered on
the top of the scene. This is basically like a overlay screen on the
top of the screen space. Camera canvas is placed at
a specific distance from the camera canvas
scalar component. It simply controls the scale and pixel density of
the UI elements. Kale is your size. Pixel density is the number
of pixels in the given area, basically for the UI elements. Now there are some scale modes available in canvas,
scalar component. First, is your
constant pixel size. The size in pixels for
the UI elements remain constant here irrespective
of the screen size. Second is your scale. With screen size scales, the UI elements on the
bigger screen sizes, the UI elements placed on the canvas will scale up
according to the screen size. Here, if you choose the
canvas scalar component. Lastly, we have
constant physical size. The physical size of
the UI elements remain constant irrespective
of the screen size. I'm here in the Unity editor. We have already created a scene, and the name of
the scene is UIC. Let's create a canvas
component here. How do we do that?
Right click here, the UI scene, and
select Game Object, and then select UI here. Inside UI, we will have
to choose canvas here. Okay, and that's it. Our canvas component here
is added to the scene. We won't be able to see anything here because we have
not added any elements. Basically, this
will be a parent of all other UI elements like textboxes and
buttons, et cetera. We have a W transform
component attached automatically or added
automatically to the canvas. Game object transform
basically will place all the other UI elements inside the specified area
or the canvas. Okay, so as we all can see here, again some values
driven by the canvas. So this is a non
editable rec transform. We cannot edit it right
now because render more to screen space overlay or
screen space camera, then we won't be able to edit
the canvas rec transform. But if we change
it to world space, then we will be able to change or modify the transform here. Okay, then we have
canvas scaler here. First is your
constant pixel size. Then we have scale screen size, and we have constant
physical size. I will see you in
the next session with more UI components.
Thank you so much.
29. UI Text & components: Hi friends, My name
is Rohan was in the last session we spoke
about UI Canvas Unity. In this session, we're going
to talk about UI Text Unity. So what is UI Text
Unity? Very simple. It displays a piece of information
or a text to the user, which is generally
non interactive. This information can
be a score, a health, number of coins, et cetera, which are generally
displayed using UYext. In the game or in a
C UI text component is attached to a game object. This means when you create
a UI text component, a game object is created to which UI text component
is attached to. Now there are sum
of properties for a text element I text element, these are font is
used by the text, the font that is used by
the text, The font size, which specifies the size of the styling or the style
that is used by the text, is the value the text
component displays. Line spacing is species,
font, line height. And alignment is positioning of the text middle,
center, top, bottom. Okay, now let's get into
the Unity editor and let's create a UI text
element inside Unity. Okay guys, I am in
the Unity editor. And to create UI text, it's similar to how we
created Unity canvas. Right click on the UI here
and go to Game Object. And select UI. And select your text
element here. Here it is. Your text is created. So we can see text on
the screen over here. So this is a text
game object here which will have a rec transform
here, which is editable. We can modify the
position to it. Now, Text game object will have component
text attached to it. Now you can see here, this is where we can
put in the text. Okay, right now it's new text. Let's put a long text here. Let's try to change
it so that we can see the entire content. Font style is normal. We can change it to bold, italic, bold, and italic. Let's change it to bold here. Then we can increase or
decrease the font size. Let's change it to 18 here, okay, it's become bigger. Now in the paragraph, this is alignment where
we can align the text. Basically keep it in the center. This rectangle that
you can see here is the transform for the text box. Then we have
horizontal overflow. Here we have a long text and we are not able
to view the text, the entire text right now. It's wrap, we can
change it to overflow, but still we are
not able to see. What we can do is we
can click here and increase the transform
for the next. Let's keep this wrap here, and let's increase this. Let's increase this
according to our text. Let's change the
text color here. Let's keep it to red. Here it is. That's it guys.
Thank you for the session. In the next session
we'll be talking about UI image component in
Unity. Thank you so much.
30. UI Image & components: Hi friends. My name
is Rohan Vasudev. In this session, we are
going to talk about UI image component in Unity. What is an UI image component? Ui image component displays an image to the
user on the screen. Ui image component
can be used as icons backgrounds for the
text components, et cetera. So there are various
scenarios for which UI image component can be used for UI image require source image or texture
to be a sprite. So the source image or the image for the image component
has to be a sprite. What is a sprite? Sprite is a simple two degraphical object
having textures on them. Now, there are a few properties for an UI image component. What are these properties? Source image, source
image is basically the image to be displayed in the form of a
texture or a sprite. Then we have another
property, which is color. Color specifies the color
applied to the image. Then we have material. Material is the material
used to render the image. Preserve aspect,
preserve aspect, preserves the aspect or actual dimensions of the
image set native size. It changes the dimensions
of the image rec transform to the actual pixel
size of the texture. Then we have one more property for the UI image component, which is image type. Image type will specify how the image is displayed
on the screen. There are four image
types which can be used. First is your simple. In this image type, images are stretched
to fit transform of the image component or
the image game of check. We have sliced specifies a sliced image for rectangular elements
or decorated boxes. Then we have tiled image with
the repetition of sprites. The sprites or the textures
are in repetition manner. If we select the
image type to tiled. Then lastly we
have a filled type which is a partial image generally useful for your
countdown, timers, et cetera. Okay, now let's get into the Unity editor and let's
create an UI image component. Here it is, guys. I'm
here in the Unity editor. Let's create our image component here in the C. Okay,
how do we do that? Right click here
on the UY scene, go to Game Object, select UI here, and
click on Image. Here. We have created our
image component in the scene. Right now it's blank
because we have not attached any
source image here. This source image has to be a sprite to attach
a source image. Let's create a
sprite inside Unity. How do we do that? Let's
create a folder here, just right click here, inside the Acts, and
go to Create here. And click on Folder. Okay, let's rename the folder to sprites and just
open the folder. This is the image that
we are going to use. So let's just drag and drop this image into the
sprites folder here. Just drag and drop
the image here. Okay? So right now, this image by default
is an image format, so we need to change it to a sprite format. So
how do we do that? Click here on Default and select Sprite to
D and U, Y here. And click on Apply here. Okay, we have
created our sprite. Let's attach this sprite
to the image component. So click on Image
Component again. Okay, And click here. And select this at, which is a sprite now. Okay, and that's it. We can see our UY image component
added inside the scene. Then we have preserve
aspect here. Preserve aspect will actually preserve the original
dimensions of the image. Let's change the width to 150. Okay? Right now it's
not looking good, it's looking a little stretched. If you choose
preserve aspect here, it will return the actual
dimensions of the image. So let's see what is
native size here. This is a re, transform
for the image. So once we click on
this native size, it will return or
change the transform, this rectangle here to the actual pixel
size of the texture. Okay, so let's just click on Set Native size here.
Okay, and that's it. It has modified
direct transform to the actual pixel
size of the texture. So that's it guys, That's it for the image component here. I will see you in
the next session with the UI button component. Thank you so much guys.
31. UI Button & components: Hi friends. My
name is Rohan Dev. In this session,
we're going to talk about UI button immunity. What is UI button immunity? It is an interactable
element immunity which responds to
the user click. It is used to perform or initiate an action in
the scene or a game. An image component is
attached to the button whenever you create a
button immunity by default, an image component is
always attached to it. So you can apply any image to
the button of your choice. So what are the properties
of a button element? First, is your interactable, which specifies if the
button is clickable or not. Then there is transition, which specifies the process of changing from one
state to another. Okay, so basically when you tap on the button or
click on the button, the state of the button changes. And these states can
be your normal state, your highlighted state
pressed, and disable state. There are four options in transition. What
are these options? First is your nun. Then
we have color ten here. Then we have sprite swap here. And lastly we have animation. Now let's see one by one what these options for
transitions basically mean. None will have no effect
on the state change. It will have no
effect on the button, basically whenever the
button is pressed or whenever the button is disabled or whenever the
button is highlighted. Then we have color tint, which changes the color of the button with the
change in the state. So we can have different colors for different states here, sprites, different sprites can be displayed for each
individual state. So we can apply
different sprites for each individual state here. Lastly, we have animation
transition here. Animations can be played according to the
state of the button, so we can apply animations to the button according
to the state. A button must always have an animator component
attached to it in order to allow the
animation transition to work. Okay, so now let's get into the unity editor and let's create a UI button in the Unity. Okay guys, here I am
in the Unity editor. And let's create a button
here to create a button. Just right click here
on the UI scene, okay? And just go to Game Object, and then select UI here. And then click on button here. Okay, so we have our
button created here, as we all can see
here in the screen. Now let's see what
are the elements attached to the button
game object here. Firstly, it will
be a rec transform that will be attached
by default here. Okay, Then we will have
an image component which will be attached
when we create a button. Now going to the
button component, here we have an
interactable property which is checked right now. Let's run the okay. Right now we are able to
click on the button here, and it's a clickable
button basically. Okay, let's just uncheck this. And the button is disabled here. We cannot click on the
button here, okay? Then we have
transition property, which will have
four options, none, color, tint, sprite
swap, and animation. Choosing none simply means
that button will have no effect on the state
change here, okay? But by default it is
set to color tint here, so let's try and see
what is color tint here. Okay, Target graphic. Target graphic simply means the image that is set
to the button here. In this case, this image has
been set to the button here. Then we have normal color. Normal color is the color
basically which is applied to the button when the state
of the button is normal, when it is not pressed
or highlighted, basically currently it
is kept to white color. Let's change the normal
color of the button. Let's keep it to yellow color. Okay? Highlighted color is basically when you hower
on the button here, let's change that
color to red color. Okay? And pressed the state when you actually
click on the button. Currently it is gray. So let's change
it to this color. Okay. And selected color is basically when the button
is in the selected state, let's keep it to white. Okay? And disabled color is when the button
is not interactable, basically, when you
uncheck this thing. Then lastly we have an
onclick function here. Okay? On click function
is a Unity function, which is triggered when the
button is pressed here. We will get into the
details of this in the upcoming sessions when we are going to
learn about events, triggers, and
functions in Unity. So right now, the button
is in the normal state. In the normal state, the button
will have a yellow color. Okay? Highlighted
color here is red. So if I hover on
the button here, the color of the button
will turn to red. Okay, then pressed,
color is pink. So when I click on the button, okay, you can see here,
it turns to pink. And once I leave the button, or leave the click, then it will turn
to white because that's a selected
state of the button. Okay, it turns to white here. Lastly, if you extend a
button component here, okay, or the button game object here, inside the button game object, we will have a text game object. Okay, where we can actually
apply the text on the button. Right now the text Is button, so we can change it to Submit
or the text of our choice. Okay. The text on the button
will change to Submit. Here. That's it guys. Thank you for the session. I will see you in
the next session. Thank you so much guys.
32. UI ScrollView & components: Hi friends, My name
is Rohan Vase. In this session, we're
going to talk about UY scroll view in Unity. What is UY scroll view? Uy scroll view is
used to display content inside a
scroll able frame. It is generally used
when a large content needs to be fitted inside
a small area in a scene. A scroll view has a scroll wreck and an image component
which is attached to it. When you create a scroll
view game object, by default a scroll wreck and an image component will
be attached to it. A scroll wreck provides
functionality, scroll over the content, which takes up a lot of
space and needs to be fitted inside a small
area in a scene. Now there are some important
elements in a scroll view. First is your Viewport. Viewport is the child of the root game object
which is scroll view. It is a rec transform
that actually acts as a window to the
scroll level content. Now mask component is
attached to the viewport in order to hide any content
outside of the viewport. Then second we have content. Content is the child of
the Viewport game object, The content
component, we'll have all the scrolling
content inside it. So basically whatever
content we are going to put in a scroll view will
be inside your content, game object, or
content component. The size of the
content component needs to be expanded to fit all the scrollable content Only if the content is larger
than the viewport, then the scrolling
effect will work. So suppose if content is
smaller than the viewport, then the scrolling effect
won't work at all, so it has to be larger
than your viewport. Then we have scroll balls. There are two types
of scrollbars here, horizontal and
vertical scrollbars, which are the child of
the root game object, which is your scroll
view game object. Again, they're used to define horizontal and
vertical scrolling for the scroll bar elements. So horizontal scroll bar is used to define
horizontal scrolling, and vertical scroll bar is used to define
vertical scrolling. How to make a
dynamic scroll view. Now the scrollable content is added inside the
content component. Okay, so whatever objects
we are going to add, they all will be inside
the content component. The size of the
content component or the game object
is larger than the body of the scroll view by default and can be
modified as required. Now this perfectly suits for the static scroll
level content, if we exactly know how much
content is going to be there inside the
scroll view basically. But what if we don't know how much content is
going to be there? What if the content is added
at the run time? Then what? Then the content component
will not adjust its size accordingly and the
content outside of the content area
will not be visible. Hence, the size of the
scroll view can be changed dynamically by
adding two elements to the content component. And which are these elements? These are your
vertical layout group. What is vertical layout group? Vertical layout group is used to lay out child elements
below each other. Okay? Below one another. The scroll able
content here will be placed vertically,
one below another. Then we have Horizontal
layout group. Horizontal layout
group is used to lay out child elements
side by side. The scrollable content
here basically will be placed horizontally,
side by side. Okay? And then lastly we
have content size fitter. What is content size fitter? The most important aspect here, content size fitter will drive the size of the rec
transformers attached to. Okay, so this Content size
fitter basically will be added to your content
component or game object. In fact, even the
vertical layout group or horizontal layout group will be added or should be
added to your content, game object or
content component. Content size fitter will drive the size of the rec
transform it's attached to, based on the layout
of its children. It only works in the combination
with a layout component such as your vertical
layout group or horizontal layout group. Content size fitter
can be said to have a horizontal fit preferred size for horizontal layout group. So we can set the horizontal fit to preferred size for
content size fitters. So this is a property
for content size fitter which can be
set to preferred size. This will basically
increase the Id on adding more child objects and which will fit them all.
So that's it guys. I will see you in
the next session. In the next session, we'll
be creating an example for a scroll view with a
vertical layout group and a content size fitter. Thank you so much guys.
Thank you so much.
33. Create vertical ScrollView using Vertical Layout group: My friends, my
name is Rohan Sev. In the last session we spoke about UY scroll view in Unity. In this session, we
are going to create a scroll view inside Unity with vertical layout
group and content Size Bitter. Let's create a scroll view
here. How do we do that? Just right click here
on the UY scene, which is your name of the scene, and go to Game Object, go to UY and select
Scroll View Here. Yes, our scroll view
has been created here. Okay, We can just go
to the scene mode here and adjust the width and
height of the scroll view. Just click on Wreck Tool
here and just adjust the inside the canvas scroll view
game object created here. Scroll view will have image
component attached to it by default and a scroll wreck attached to it by default. Horizontal and vertical here is in what direction
it will scroll. Right now, both of
them are checked. Then we have a moment type
which is kept to elastic. Elastic will basically move the intent in all
the directions. We don't want to do that. Let's change it to clamped. Okay, then inside
the scroll view, we'll have a viewport here. Let's go to viewport here. Viewport basically, again,
we'll have an image component attached to it with
a rec transform and a mask attached to it. Now inside the Viewport, we'll have a content which will basically have all the
scrollable content. Okay? Whatever the
scrollable content we need to put here needs to go inside this content component or content game object here. Let's add vertical layout
group to the content here. Okay? And let's add
content size fitter here. Okay, for the vertical layout
group, we have padding. Okay? Padding is
basically the space that will be left from left to
right, top and bottom. Okay, let's keep it to 55. We can adjust it later also. Okay, then spacing is basically the space between two
different elements, child elements inside
the content game object. Let's keep it to five here. Again, scroll able area basically
is not horizontal here. We don't need to
change this, okay. We will have to change vertical. Fit here to preferred
size so that even if you keep on adding
more child elements to it, content area basically
will resize itself. All the elements
will fit into it. Let's start adding images
inside this content here. But we need to do some
changes in the image here. We want it to be a
little stretched. Okay, let's go to scene here. Select again, rec tool here and adjust it
according to the. Just drag it. Let's right click on the image
game object here. Go to UI here again, and click on text here. We have added one image
here to the scroll view. Let's add more images so that we can see the scrolling effect. Okay, so let's
just press control D and keep on adding the images. Copying the images basically for the scroll bar,
horizontal and vertical. In this case, Horizontal
is going to be disabled because we have used
Vertical Layout Group here. Click on scroll
bar vertical here. And let's just change the width for this,
just make it five. Okay, for horizontal we
need to change the height. Let's keep it to zero. Now let's run the scene, and let's see how it looks. Here it is. We have a
scrollable view here. As we discussed earlier, image component
will be attached to the scroll view
game object, okay? And a source image is set to
background here by default, so we can change
the color for it. Let's change it to darker color, or maybe red color or
something like that. Okay? Depending again, it
depends on what color you want, what color combinations
you're using. Okay, here is the scroll view using vertical layout group
and a content size fitter. Thank you so much guys. In the next session we'll be talking about or
we'll be creating a scroll view using a horizontal layout group
and a content size fitter. Thank you so much, guys. I will see you in the next
session. Thank you so much.
34. Create horizontal ScrollView using Horizontal Layout group: Hi friends. My name
is Rohan Asad. In the last session,
we saw an example for Unity scroll view using vertical layout group
and content size fitter. In this session, we are
going to see an example for Unity scroll view using Horizontal Layout Group
and Content Size fitter. So basically the scroll
view will scroll, the content inside the
scroll view will scroll in a horizontal direction
to create a scroll view. Right click here
on the UI scene. Go to game object here, select UI here, and
click on Scroll view. Also, let's adjust the height and width for the scroll view. There are two ways to do it. Either you can click
here on the Re tool, go to scene mode, and just drag this thing. Or else you can directly set the width and height
for the scroll wheel. Let's just change the
width to 400 here, since it's a horizontal
scroll view. And let's keep the
height to 150 here. Let's just extend the scroll
view game object here. Okay, extend the
Viewport game object here and click on content here. Let's go to scene mode here. Let's adjust the height
of the content to match the height
of the scroll view here using a transform tool. Again, for the scroll bars here. Scroll bar horizontal. Okay, let's adjust
the height to five. Okay, for the scroll
bar vertical, let's keep the width to zero, because anyways, the content is not going to scroll
here vertically. Let's keep the width to zero. For the scroll bar
vertical here. Again, go to Scroll View here. Click on the scroll
view game object here. And keep the moment type to
clamp here and not elastic. Now let's add some images
in the content, okay? But before adding those images, let's add two components here. Okay? One is your
horizontal layout group, Another is your
content size fitter. Click on Add Component here, and select Horizontal
Layout Group. Okay? Padding left
right top will adjust it later according to the sis and the look
of the image here. Okay, For the child alignment, we want scroll able content exactly in the center of
this scroll able view, basically from upper left. Change it to middle
center here, okay? And then add another component which is your
content size fitter. Okay, Horizontal fit, we will change it to
preferred size here. All right, after doing this, let's add image here. To add an image in the
content right click on the content game object. Go to UY and select Image here. Our image is added
here in the center. Okay, now let's do one thing. Let's set a sprite
for this image. I have already
added a few sprites here in the sprites folder here. Let's just drag and drop
this user one sprite in the source image for the image basically
that we just added. Okay. Click on
preserve aspect here, just select the image
and press control D to copy the image. Okay, let's just keep on
adding the images, okay? Now click on image one, and let's just change
the source image. For that, just change it, drag and drop the source
image here, right? Basically, just click on
the content here, okay? And go on the horizontal
layout group here. And let's adjust the
padding for this. Let's just keep it to five, okay, For the right again, let's just keep it to five. For the top, let's
change it to ten. Bring it more in the center. Okay, bottom. Let's
keep it to zero. We don't want to
change it for spacing. I think spacing looks fine here. Okay. Okay, that will be all. Let's run the scene and let's see how this thing looks here. We have just created a scroll view using a horizontal layout group
and a content size fitter, Though this scroll
view basically will scroll only in
horizontal direction. Okay, thank you guys. Thank you for the
session. I will see you in the next session. Thank you so much, guys.
35. UI InpuField & components: Hi friends, My name
is Rohan Vase. In this session, we're
going to talk about UI input filled in Unity. Basically, it turns
a simple label into an interactive
input field element where you can take
inputs from the user. So it is generally used to
take user input in Unity. Generally, it is
used for logins, registrations, or get
any kind of flare data. A text component or a
text game of created when you create an input field
component as a child object. Now, there are some properties
for input field element. What are these properties? Interactable. Interactable
property specifies the input field can take
any user inputs or not. Then we have
transition property. Transition property is
used to determine how an input field would
react in normal pressed, highlighted, selected
or disabled state. Okay again, we have text
component property. Text component
property basically refers to the text
component here. It is a reference to the
text component which is the text game object
which is created as a child object for the
input field component. Then we have text is
the initial texting the input field before taking
the user input, basically. Okay. Then we have
character limit. Character limit specifies
the maximum number of characters and
input field can take. Then we have some
more properties for UI input filled in Unity. Content type property
specifies the type of characters and input
field can take example. It could be a
standard character, it could be an e mail address, it could be a password, it could be an integer number, or it could be a decimal number. Then we have line type. Line type specifies format of the text in the input field. This format can be further
classified into three types. Single line, the
text is allowed to be in a single line here, okay? Then we have multi line submit. The text can use multiple lines
only when it is required. It simply means
that the new line is automatically added
by the input field here. Okay, so multi line, new line is again the text
which can use multiple lines. A new line can be added by the user by pressing
the return key here. Then we have a
placeholder property. Placeholder is a character or a string that takes the place of the final text or data
as a hint or a caption. So basically it is a hint
for your final text data. Then we have carrot blink rate. Caret blink rate defines
the blink rate for the mark placed in the input field indicating the text
insertion place. Then we have selection
color selection. Color is the
background color for the selected text
in the input field. Whatever text you select
in the input field, selection color will specify the background color for
that particular text. Then lastly, we have some functions for the
input field in Unity. First, is your On
value change function. On value changed function is an Unity event called when the text in the
input field changes. Basically, when you type
something inside the input field on value changed function is
called or invoked in Unity. Lastly, we have on
end edit function. On end edit function is an Unity event
called when the user submits the text inside the input field by
submitting, okay? It is even called when the focus is removed
from the input field. Okay, so that's it guys,
thank you for the session. In the next session
we'll be seeing an example for input
field in Unity. Thank you so much guys.
36. Create UI InputField & understand the components: Hi friends, My
name is Rohan Sev. In this session, we
are going to create an example for UY
input field immunity. To create an UY input field, let's right click
here on the UY scene, Go to game object, go to UY and click on Input Field Ear Input Field
has been created in Unity. Now let's extend the
Input field game object inside input field game object. We'll have two game objects,
Placeholder and text, that will be created by
default, her game object. Here is the hint text basically, which will be inside
the input field. Right now. It is
set to enter text. Let's change it to name. Here, yes, our placeholder
text has changed now. Initially it was entered text, we have changed
it to enter name. Here we can see the change
here inside input field. Okay, This text game object is basically the which will be the user input the text that will be taken
from the user here. Okay, let's go to input
field game object here. Again, when you create an
input Field game object, it will have a Rec
transform component by default attached to it. Right now, the width
and height for the Rec transform
is set to 160.30 Let's change it to
170.70 here, okay. So we can change the size
for the input field by adjusting the rec transform
for the input field again, it will have an image
component attached to it, so we can change the color. We can change the
source image as well. Okay? So coming to the input field component for the input field game
object here, okay? It will have an
interactable property right now it is checked. It simply means that it will be able to take the user input. So if you uncheck this, it won't be able to take
any input from the user. Then we have
transition property. Transition property
basically specifies how the input field will react to the change in the state or the state change coming to the text component
property here. Text component property here is the reference to the
text game object here. Okay, again we have a
text property here. Text property here
is the initial text that we can add before
taking the user input. Then we have character
limit property. Limit basically
specifies the number of characters this particular
input field can take, okay? So right now there is no
restrictions on the character, will set the character
limit to zero, okay? Then we have another property
which is a content type. Content type basically
specifies the type of content this input
field will take, okay? There are various options here. We have a standard, then we have auto corrected integer numbers, and we can use decimal number. Then we have name, e, mail, ID, password, and film. We can also set a custom
content type here. Then we have another
property which is line type. Line type specifies the format of the text inside
the input field. Okay, There are three
options for that. Single line. Single line allows the text only
in a single line. Okay, We cannot have
multiple lines. If we use single line property, then we have multi
line submit here. Okay, let's change it
to multi line submit. And let's run the scene. And let's see how this
thing works here. Okay, let's try adding a long text here inside
the input field. This is a long text to okay, multi line submit
property. Okay? So as you can see here, new line is automatically created upon adding
the text here. Okay? Then we have a
placeholder property. Placeholder property
is a reference to your placeholder game
object here again. Then we have a carrot. Carrot is the mark, which is actually the place for the insertion of the text here. So you can see a
mark blinking here, that is the carrot
inside input field. Okay? So you can increase or decrease the blink cat
for the carrot here. Then we have a carrot width. So let's try changing
the carrot width, okay, So the width of the
carrot increases here. If I change it to four, okay, Then we have custom
carrot color property here, custom carrot color. We can actually change
the color for the carrot. Right now it is black. Okay, we can check this custom carrot property
here, color property here. And change the carrot color
the way we want it to. So let's change it to red. So you can see here right now
it's turned to red color. Okay, Then we have
another property which is a selection
color property. Right now it is set to blue. Selection color
property is basically the background color
for the selected text. So let's select a text here. So this is the
background color for the selected text,
which is blue color. Let's change the color
to something else. Okay, let's make it a
little dark, probably. Yeah. Okay, So we can change the background color for
the selected text here. Then we have two functions here. First is your on value change. On value change is the Unity
event which is invoked when the user is typing something
into the input field here. And lastly, we have
on edit function, which is an Unity event again, which is invoked when user
submits the text from the input field or even if you remove the focus
from the input field. We will get into the details
of these functions when we proceed further with
the sessions where we learn about events
and functions. Okay, so that's it
for the session guys. I will see you in
the next session. Thank you so much guys.
37. UI Slider & components: Hi friends. My name
is Rohan Vasudev. In this session,
we're going to talk about UI slider Unity. What is UI slider immunity? It is a standard slider
which is used to set a certain value between minimum
and maximum value pair. It is commonly used
for audio controls and screen brightness in
a scene or in a game. Now, when you create a
UI slider component, Unity three game objects, background fill area, handle, slide area, are also created
automatically as the child. For the root slider game object, what is background game object? Here, background game
object has a Rec transform, an image component
attached to it. This image will be the background image for
the slider fill area. Fill area again has a Rec transform component
attached to it and spans or extends from minimum value to current
value of the slider. A child game object for the fill area game object is
also created automatically. This game object will have a transform component and an image component
attached to it. This image component specifies the image and color for
the fill game object. What is handle? Slide area? Handle slide area has
a transform component attached to it and follows the
current value of a slider, a child game object
handle for the handle, slide area is also
created automatically. This handle will have a re transform component and an image component
attached to it. This image component specifies the image and color for
the handle game object. By default, Unity
Knobprt is attached to the handle game object as the image properties
of a slider element. Interactable property
specifies if the slider is
interactable or not. Transition property is used to determine how a slider would
react in normal pressed, highlighted, selected
and disabled state. Fill is a transform to us as a fill for the slider
and is a reference to the fill game object
which is created when you create a slider
component in Unity. Handle is again a transform to use as a handle for the
slider is a reference to the game object which is created automatically when you create a slider component in Unity. Direction is the
direction of the slider from minimum to maximum value. We have four options for the
direction left to right, right to left, top to
bottom and bottom to top. Minimum value is
the value set for the slider or allowed
for the slider. Maximum value is
the maximum value set for the slider or
allowed for the slider, value is the current
value of the slider. And lastly, whole numbers is
basically a bullion value. If it is checked or
if it is set to true, then only whole numbers
will be allowed between minimum and maximum
values for the slider. That's it guys. I will see
you in the next session. In the next session,
we'll be seeing an example for UI
slider in Unity. Thank you so much guys.
38. Create UI Slider & understand the components: Hi friends. My
name is Rohan Dev. In this session, we
are going to see an example for UI
slider in Unity. To create a UI slider in Unity, right click here
on the UY scene, go to game object, go to UI and select slider here. Our slider is created in Unity. Select the slider here, and go to Inspector Taber. And we can see Rec
transform component attached automatically to
the slider game object. By changing the width and
height of the Rec transform, we can basically change the weight and height
for the slider. Coming down here, we have
slider component attached to the slider game
object by default. Okay? So we can see some properties here for the slider component. Interactable property
basically will specify if the slider
is interactable or not. Right now it is checked, that means the slider
is interactable, okay? Then we have
transition property. Transition property is
used to determine how this slider would react in a state change or react on
a particular state change. Coming to the fill
wreck property here fill wrecked property basically is used as a
fill for the slider. It is also a reference to the Rec transform fill transform which is created automatically inside field area game object. Okay, Handled Reck property here is used as a handle for
the slider and again is a reference to the
handle game object which is created automatically
inside handle slide area game object in the
slider direction property will specify the direction of a slider from minimum
to maximum value. Okay. We have four options for the direction property
left to right, right to left, bottom
to top, top to bottom. Okay. Let's run the
scene here and let's see how direction property
works for a slider. Currently, the direction of the slider is set
to left to right. This slider will move
basically from left to right. Okay, Let's change
it to right to left. This slider basically will
move from right to left, and then we have bottom to top. Okay? This slider will
move from bottom to top. And then lastly, we
have top to bottom. This slider will move
from top to bottom. Okay, Let's change
it to default, which is left to right here. Okay? Then we have min value. Min value is basically the minimum value which
is set for the slider, currently it is set to zero. And max value is the maximum value which
is set for the slider. Currently it is set to one. Let's change it to 100, okay? This value here is the
current value of the slider. Okay? Let's move the slider, or move the **** here, okay? We can see decimal numbers here when we move the
slider, basically. And we can see the
value changing value is basically the current
value of the slider. Right now it is 24.83 and
it is back to zero again. So let's check the
whole numbers here. Whole numbers will allow the minimum and maximum value only to be whole numbers, okay? So let's check the whole
numbers property here. And let's try moving
the slider again. The changing value we can see
here is all whole numbers. We cannot see decimal
numbers here anymore, okay? And this is happening
because we have just checked the whole numbers property here. Okay? So that's it guys. That's it for the slider
component in Unity. I will see you in
the next session. Thank you so much guys.
39. Anchor UI elements in Unity: Friends, my name is Rohan Vdv. In this session we're going to create an example for resizing, scaling and anchoring of
UI elements in Unity. So to do that, let's create
a UI button in Unity, Okay, right click here on
the main camera, go to UY and click
on button here. Okay, so our button is
created here in Unity scene. What if we want to
display this button exactly in the left bottom
corner here of the scene, irrespective of screen
size or resolution. Unity provides us with
few aspect ratios here. Right now it is set
to free aspect. We have aspect ratio
of five is to four, that we have four is to three, that we have three to two, that we have 16 by ten, we have 16 by nine and we
have stand alone 1,024.2 768. We can also add
more aspect ratios. Okay, Let's set it to
free aspect as of now, which is default aspect
ratio, basically. What if we want to show this button here in
the extreme left, bottom of the C. Try setting this button here just
by dragging the button here and setting the
position for the button. Okay, for this
particular screen size, the button is here at the
bottom left of the scene. Let's try changing the aspect
ratio to five by four. No, it's not correct, it's going out of the scene. Okay, let's try changing the aspect ratio
to four by three. Let's try changing the
aspect ratio to 16 by nine. It's not proper because we want this button to be anchored at the exact position irrespective of any screen size or
any screen resolution, or any as ratio. Okay, now let's try doing that. To do that firstly, let's click on the canvas here. Okay, for the canvas, we have a canvas scalar
component attached to canvas game
object For Y scale, more changed the scale mode from constant pixel size to
scale with screen size. Okay, now let's click
on button here. Now we want to anchor
this button at the bottom left of the screen. So to do that for
the rec transform, Unity provides us with
some anchor presets here. Okay, this is
vertical anchoring, and this is horizontal
anchoring basically. Okay, So we want this button to be anchored to left vertically, so click on left here, okay? And we want this button to be anchored at the
bottom horizontally, so let's click on bottom here. Okay, so this way
the button will be anchored in bottom
left position. Now let's go to the
scene mode here. And let's just again
drag the button here and set the position for the button the
way we want it to. Okay, now let's go
to game mode again. And let's see the position
now for 16 by nine screen. Yes, it is at the
bottom left corner. Let's try changing
it to free aspect. Yes, it's at the same position. Let's try changing
it to five by four. Yes, let's try changing
it to four by three. Let's try changing
it to three by two, then let's try changing
it to 16 by ten. And let's try changing it to
stand alone, 1024 into 768. Let's create another
text element. And let's anchor it at the top left position
here in the screen. Okay, so to create a UI text, click right click
on the canvas here, go to UY and go to text here. Okay, our text is created here, exactly in the center
of the screen. Okay, select your
text game object, go to Rec Transform, Anchor presets here, okay? Vertically. We want it
to be anchored left, okay, Horizontally, we want
it to be anchored top. Let's select top here. Now again, let's go to
the scene mode here. And let's track the text element here or text game object here, exactly at the top corner here. Now let's go to the
game mode again. Now let's try changing
the aspect ratio. Let's try changing
it to free aspect. Let's try changing
it to five by four. Let's try changing
it to four by three. Let's try changing
it to three by two. Let's try changing
it to 16 by ten. Let's try changing
it to 16 by nine. Let's keep it to free aspect. Okay, so this is how you
basically anchor scale or resize an UI element or
any UI component in Unity. Okay, that's it for
the session guys. Thank you so much. I will
see you in the next session. Thank you so much guys.
40. Introduction to Unity Events: Hi friends. My
name is Rowan Suv. In this session,
we're going to talk about event functions in Unity. What are event
functions in Unity? The code inside the Unity
script does not work like a traditional code in any other program
or any other code. Instead, Unity passes control to the script by calling
certain functions within it. These functions are called
event functions as they are executed in the response to certain events during
the game play. Unity identifies
these functions on the basis of their names
given by the Unity itself, and executes them according to the event during the game play. Some of the important
event functions in Unity are as follows. We have awake function, we have start function,
we have update, we have late update, and we have fixed
update awake function. The first scene of the game is loaded upon running
the game application. So when you run any
game application, the scene is loaded
and all the objects basically inside the scene
or within the scene, are initialized upon
the scene loading. Once the objects are
created and initialized, awake function inside
the Unity script is invoked and executed. Okay, Awake function in the script is basically an
initialization function, which is the first function to be executed within a script. This function is called
only once and is executed even if the script
is not enabled or active. Let's see what is
start function. Start function in the script is called only after a wake
function is called. And it is called once in
the life cycle of a script. Unlike a wake function, it is executed only if the
script is enabled in Unity. Update function is defined in the Monobehavior
class and will run automatically in each frame of the game if the
monobehavior is active. What is frame?
Frame is basically one still image that is
rendered on the screen. Okay? The update function runs periodically while
our game is running. The update function is invoked
or called once per frame. The calling of an
update function depends on the frame rate for the
game. What is frame rate? Frame rate is basically
the frequency at which the consecutive steel images
are rendered on the screen. The time interval will
be basically low for high frame rates and will be
high for the low frame rate. Late update function is called once per frame after the
update has finished. Calling. The late
update function behaves exactly in a similar manner to that of an update function, except that it is called only after the update
function is called. This function is basically
commonly used to make the camera
follow the player or any other game object. Then lastly, we have
fixed update function. Fixed update function does
not depend on the frame rate. Fixed update will have
constant time intervals. Fixed update function can be
called multiple times per frame if the frame rate is low or it may not be
called per frame. If the frame rate is high, it is quite possible that
fixed update will be called more than the
update function. Okay, That's it guys, That's it for the session. In the next session, we'll see an example for start update, late update, and fixed
update functions. We'll also see the
difference between them. I will see you guys
in the next session. Thank you so much guys.
41. Understand Unity Event functions in a script: Hi friends, my
name is Rohan Sev. In this session, we
are going to see an example for a wake start, update, late update, and fixed update functions
within the script in Unity. For that purpose, we have already created an
empty game object here. And the name of the empty game
object is event functions. We have also created a
script, event functions. Let's open the script here. Okay, let's add a wake function, late update function, and fixed update function
to the script. Okay, guys, we have
added awake function, update function, and
fixed update function to the script here, okay? Awake function is the
initialization function basically. And it will be the
first function to be called within the script. When you run an application, any gaming application, the objects are first
initialized and created. Once the objects are
created and initialized, awake function will be invoked and called
inside Unity script. Let's print something
inside the awake function. This is an awake function, okay? So coming to the start function, start function will
basically be called only after the awake function
is executed, okay? Start function will
be called only once in the life
cycle of the script. Let's print something inside
the start function as well. Start function. Okay, coming to the
update function here, update function will be called only after the
start function is invoked. Update function will be
called once per frame. The calling of the
update function totally depends on the frame
rate of the game. Let's print something inside
the update function as well. Okay, update function
is executed. Let's add a function in Unity which is time
dot delta time. Basically, time dot delta
time will actually tell us the time taken for the completion
of the last frame here, okay, Coming to the
late update function, update function again
is called one frame. It is exactly like
update function, but the only difference is
that update function will be called only after update
function is executed. Update function
can be used if you want your camera to follow the player or
something like that, or maybe you want your camera to follow any other game object. Let's print something inside
late update function. Late update function is executed again, Let's add time delta time. This will tell us the time taken for the completion
of the frame. Basically coming to the last
fixed update function here, fixed update function
basically does not depend on the frame
rate of the game, okay? The time interval between fixed update functions being called is always
constant in Unity. Let's print something again inside the fixed
update function. Okay? Update is executed at, let's add time delta time again. Okay, let's go and
run the senior. Okay, guys, here is the
output for the code. This is an awake function. Awake function will be the
first function to be executed. Then we have start function that will follow the awake function. Then later, fixed
update, update, and late update functions
will be executed. Fixed update function does not depends on the
frame rate and the time interval in the fixed update function will
always be constant, okay? So all the fixed update
function basically will have 0.02 here, okay? As the output update function
and late update functions, they both have 0.02 as
the time interval, okay? But if we go down, this time is changing here for both update function and
late update function, since both these
functions depends on the frame rate of
the game, basically. Okay, so that's it guys. Thank you for the session. I will see you in
the next session. Thank you so much guys.
42. Introduction to custom functions in Unity: My friends, my name
is Rohan Vasudev. In this session we are
going to learn about custom or user defined functions
in Unity C Sharp. So what are custom
functions in Unity? A function basically
is a block of code used to execute a
single action or a task. It provides extensibility to the gaming application
along with re, usability of the code, and saves time for
rewriting the code. A function in Unity has
following components. Function name, return type, body access specifier,
and parameters. Syntax for a basic function in Unity C sharp is as follows. First, we specify
access specifier, which is followed
by the return type, then the name of the function, followed by brackets
and calibraces. Inside the calibraces,
we provide the block of code or
the function body. Let's see one by one. What is function name?
What is return type? What is body? What
is access specifier? And what is parameters
in a function? Function name. Function
name is a name given to the function, okay? Then we have return type. Return type specifies what data type of function
would return as a value. Then we have body, has a block of code to be
executed inside the function. This body or the block of code will be inside the
function, basically. Then we have access specifier. Access specifier
specifies accessibility of a function within
the application. Pesameters is the arguments
passed in a function. This is an optional component. Now a function can be a basic function or a
function with return type, or a function with parameters. Basic function is basically a simple function
with a block of code to be executed inside. A function with return type specifies the data type of the value returned
from a function. In simple words, it specifies
the type of output. If the output type is number, then the return type can be int, float, double, et cetera. Function with parameters. Parameters is basically
the information passed to the function. These parameters act as a
variable with data type. These are variables
basically with a data type. This data type could be int
or a string, et cetera. They are passed after declaring
name of the function. Inside the bracket, you specify
the name for the function and the name of the function is followed by the
brackets, basically. Okay? Inside these brackets, you declare these parameters. Now, there is no
restriction to the number of parameters which you
can pass to a function. But every parameter has
to be separated using. You can pass
multiple parameters, but every parameter has to
be separated by a comma. Okay, that's it guy. In the next session we'll
be seeing an example for basic function with return type and function with parameters. Thank you so much guys. I will see you in the next
session. Thank you so much.
43. Write a basic function in a script: Hi friends, My name
is Rohan Vase. In this session, we are
going to see an example to write a simple
function in Unity. To write a simple function, we have already created
an empty game object. And the name of the empty game
object is simple function. Here we have also created Act, and the name of the script
is simple function. We have also attached
the script to the empty game object,
simple function. Let's open the script here and let's write a piece of code. To declare a function, we need to specify an access
modifier for the function. Let's use private here. Private simply means that
this function will not be accessible outside
of the class or outside of this
particular script. The access modifier in a function is followed
by a return type. In this case, it is void because this particular function
would not return anything. Okay? Then we need to specify
the name of the function. Let's put my function. This name could be of your
choice, it could be anything. We have just put the name
as my function here. Okay? And then we
have calibraces. And inside the calibraces, we'll write the piece of code to be executed inside the function. In this case, let's
print something in the unique console with the
help of bug lock function. This is simple function u, okay? How do we run the function just past the name
of the function, which is my function
in our case. Inside the start function. Here my function. Okay, Let's save
the script, okay? So here it is, guys.
Here is the output. This is a simple
function in Unity. So thank you so much guys. I will see you in the next, in the next session
we'll talk about, we'll see an example basically for function with a return type. Thank you so much guys.
44. Write a function with return type : Hi friends. My name
is Rohan Vasudev. In this session,
we're going to see an example for function
with return type. We have already created an empty game object
return function, and a script return function. We have already attached the script to the
empty game object. Here, let's open the
script and let's write a piece of code
inside the script. Okay, so let's add
a function here. A function with return type will specify the type of data, or the value function
will return. Let's add an access
modifier to the function. And let's add the
return type here. Let's make this function
to return a number. Let's add a return
type as eight here. And let's name the
function function type. That's the name of the function. This name could be anything
as for your choice. Okay? Now, since
is a return type, we have to specify the data that will be returned here from the function
using a return keyword. Okay, now to do that, let's declare a variable inside the function
into variable. Let's declare
variable number one, which is of data type interior. And let's assign the
value ten variable, okay? Let's just simply return this number one variable
since it is a number, okay? Now, let's just pass the function with return
inside the start function. So let's pass this function inside the debug
dot lock function, because this particular
function is going to return a number, okay? Function with return type, okay? Okay, that's it, guys.
Here is the output. So we got ten here in
the Unity console. Thank you so much guys. I will see you in
the next session. In the next session, we'll see an example for
function parameters, how to pass parameters,
enough function. Thank you so much guys.
45. Write a function with Parameters: Hi friends. My
name is Rohan Sue. In this session, we are
going to see an example for function parameters
for this purpose. We have already created
an empty game object. And the name of the
empty game object is parameter function. And we have also created a
script parameter function. And we have already
attached the script to the game object
parameter function Here, let's open the script and let's write a code
inside the script. Okay, let's declare function with parameter
inside this script. Now to declare a function, let's start with an
access modifier. Let's specify the
return type to void, because this function is not
going to return anything. Let's name the function
as my function. Okay, Now we will have to pass the parameters
inside the brackets here. Parameter is basically
an information passed to the function. This information acts as a variable which
has a data type. Let's pass a parameter here
with a string data type. String first name, this is a
parameter, insider function. Let's pass another parameter, last name of string data type
using a comma here we can pass multiple parameters,
insider function, okay? Now to print the first
name and last name here. Basically to print
the parameters here, let's use debug log function. And let's print something
inside bug dot log. Okay? Let's give a
space here, okay. Welcome. First name, okay? Plus double last name. Okay? We have used double
codes here to provide a space between first name
and last name, basically. Okay? Now, let's add the function function
inside the start function. So when we run the scene, my function will be executed. My function, we have to
pass the parameters here. Okay? And the parameters has
to be of string data type. So, let's pass first
name here, Danny. And using a comma, let's pass last name. Okay. Santiago. Okay, that's it. Okay, welcome, Danny Santiago. We have the output here. That's it guys. That's
it for the session. I will see you in
the next session. Thank you so much guys.
46. Introduction to Unity Delegates: Hi friends, My name
is Rohan Vasudev. In this session, we are going
to see delegates in unity. Sha. What are delegates? Delegates are
reference pointers to the functions or
methods in unity. The function assigned to
the delegate is treated or passed as a variable so that it can be
called or executed. A delegate works as a simple subscription
based service where the function gets
called or executed upon subscribing to that
particular delegate. The functions are basically
subscribed to the delegate. When you call the delegate, the function will get
executed or called. Calling the delegate will notify all the functions
that are subscribed to it. Syntax for a delegate in unity, har public delegate void. My delegate public static, My delegate, My delegate. A delegate in Unity
CR is defined by using the delegate keyword
followed by a return type. A member variable
is declared using the member type followed
by the variable name. So let's see some
of the types of delegates in UnityChar, okay? Single cars delegate. Single cars delegate points to a single function or method. A single function
is subscribed or assigned to the delegate
using equal to sign. So this is a syntax for
single cars delegate where we specify the delegate
with a equal to sign, we specify the name
of the function. Then we have
multicast delegates. Multicast delegate points to a single or multiple
functions or methods invoking a multicast delegate invokes all the functions subscribe to it in a sequential
manner, one by one. Functions are subscribed to the delegate using
plus equal to sine and unsubscribe from it
using minus equal to sine. So this is a syntax of
a multicast delegate. Delegate plus equals to
name of the function. That's it guys. Thank
you for the session. In the next session,
we are going to create an example for
delegates in unity. C sharp. Thank you so much guys.
47. Understand Single-cast Delegates: Hi friends, My name
is Rohan Vase. In this session, we are
going to create an example for single cast
delegate in Unity. We have already created
here two scripts here. One is your delegate handle
and the other is my script. Okay, now to begin with, let's start with creating
an empty game object. To create an empty
game object here, right click here on
the delegate scene. Okay, Go to Game object and
go to Create, Empty here. Okay? Rename the game object
to delegate object, okay? And just attach the
script delegate handle to this empty game
object here, okay? Click on Add component
here and search for delegate handle
script, okay? And let's attach the script. Let's just open the script here and let's write a piece of code. Let's define the delegate here in this delegate handle
script basically. Okay, so let's remove start and update
functions from here. We don't need them, okay? Now to define the delegate, okay, first we have to
specify the access modifier. In this case it's
going to be public. Okay, Then we are going to use a keyword delegate to define
a delegate basically. And then we have to
specify the return type, which is wide because we are not going to return anything
from this delegate. Okay, let's just specify
the name of the delegate. Let's keep it as my delegate. Okay, then let's just create a member variable for this particular delegate
that we have just created. Okay? So let's keep
the access modified to public here as well.
Keep it static. Okay? And then my delegate, okay, the name of
the delegate that we have just created here. And then just pass the
variable to the delegate. Okay, so let's
keep it as my del. Okay, that's it. Okay,
so then we have created, we have defined a delegate
as my delegate here. Okay, that's the name
of the delegate. And then we have created a
member variable, my del, for my delegate that we
have created here above. Okay, let's create a
function here which will actually work
on the button. Click on the click of a button. We are going to create
a button in the UI, and through the button we are going to call this
particular delegate. Okay, let's create a
function for that here, public void, my click. Okay, let's pass
the variable here, my Dell. Inside the click. When we are going to click the button on the button click, we are going to call this
particular function my click. Then we are going to pass this my Dell inside
the my click function, which will call the
delegate that we have just created, okay? Okay, Image is created
in the center. We are not adding any
sprite to the image, basically for this
particular example, okay? We are going to change
the color for the image. Right now it's white
in color, Okay? So we're going to change
the color using the code, Basically through the script and using the delegate as well. We have already created a script here,
which is my script. Okay, let's write a piece
of code inside the script to change the color for
the image basically. Okay, so we don't need an update function here
inside the my script. Let's create a function here to change the color of the image. Okay, so d, let's name the
function as change color. Okay? To change the
color for the image, we have to call the
component image for the image game object.
So how do we do that? Okay, game object dot
get component image. Okay? Color equals to. To apply random
color to the image, we are going to use a
function inside Unity engine, which is random dot color HSV. To do that, let's call
Unity engine first. Okay? Then let's call
random function inside it, do color H, random
dolor H, okay? And color HSV is a function. Okay? So this will basically apply random colors to the
image color component. Okay? Now, this image component
here is showing an error, basically because we need to
put using Unity Engine here. Okay, Unity Engine. Okay, now we need to call
our delegate handle here. The delegate that we
have just defined inside the delegate
handle script. We need to call my Dell here in the my script start
function basically. So how do we do that? We simply pass the reference to the delegate handle
script and then we just need to call
my del here, okay? Equals to. We can pass the
function change color to this. Okay? So the change
color function is then subscribe
to the my delegate. Okay, When we call my delegate, change color function is
going to get executed. Okay, now let's just
say the script. Let's apply this script to the image game object
on the button. Click we want to
call the delegate, okay, that we have just defined. Go to button here, and then you can see
on click here, okay? Just click on the plus sign here to add the function
to the list here. Because right now it is empty. We need add the function. We need to add my click. Okay? When we call
this function, my click, my delegate
will be called. Okay, let's add my click
function to this, Okay? Let's just drag and drop
delegate object here, okay? And then currently showing
no function because we have not attached any function,
just click on it. Go to delegate
handle, script here. Delegate handle, and just select my click here. That's it. Now when I click on
the button here, the color of the
image should change. Okay? Just select Image
Game Object here, and let's see the color changing
here on the button click and here as well, okay. Yes, we can now change the
color on the button click. That's it. That's
it for the session. In the next session, we'll see an example for multicast
delegate in Unity. Thank you so much guys.
Thank you so much.
48. Understand Multi-cast Delegates: Hi friends, my name
is Rohan Vase. In this session we
are going to create an example for
multicasts delegate. In the last session we created an example for single
cars delegate. And on a button
click we were able to change the color for
the image this way. Okay, so in this session, basically we are going to add another function
to the delegate. When you click on the button, it will not only
change the color, but it will also move
the position for the image on the x axis. Here, the difference between a single cars delegate
and a multicast delegate. In a single cars delegate, only single function can be assigned or subscribed
to a delegate. And in the multicast delegate, multiple functions
or methods can be assigned or subscribed
to the delegate. Let's add one more
function to the script. And let's call that function on this button click as well. Let's add a function
here to change the position for the image. Let's name the function as
changed position, okay? Now to change the position, we are going to use
transform dot position for the game object, okay? Basically, we are
going to change the transform dot
position and we are going to use new vector t here. New vector to function here is specifies the direction
of any two game object. Let's change transform dot
position for the image. To do that game
object do transform position equals to
new vector two. Okay? That's the
function inside unity. And we have to pass the parameters here
for a function, okay? We want to change the
position for the game object. Basically on the x axis game
object transform position x. Let's add 20 floating point every time we click
on the button here. Okay, On the y axis, we don't want to
change the position as of now position y, we want to keep it constant. One more thing, let's assign this change position function
to the delegate here, okay? Now, in the last session, we have already subscribed this change color
function to the del, okay, using equal to sine. Now, if you want
multiple functions to be subscribed
to the delegate, you need to add a
plus sine here. Okay? So let's change
it to plus equal to. Okay? Then let's again assign change position
function to the del. Okay, so do that. Let's pass a reference to the
Dl delegate again. Okay, the p equal to, let's pass the name of the
function, change position. Okay, that's it. Okay, let's save the script. Okay, let's see the
output here for the code. Just click on the image
game object here. Right now, the position X for the image game
object is zero, and position for the image
game object is zero. We are not going
to change position for the image game object, we are just going to
change position for the image game object every
time we click on the button. It's going to add 20 here. Okay, let's run the scene, and let's see the output. Okay, so let's click
on the button. Okay, it's added 20 to it. One more time I
click on the button, it's 40 now 60, and yes it is. Changing the position
and the color as well. So that's it guys. Thank
you for this session. I will see you in
the next session. Thank you so much guys.
49. Introduction to Delegate-Events: Hi friends, My
name is Rohan Sud. In this session, we
are going to see what are events in unity. C sharp. Basically, we can
use events with delegates in Unity
Sharp. What are events? Events are special
multicast delegates which act in the same way
as that of delegates. Unlike delegates which can
be called by other scripts, events can only be called from within their class. Or script. Difference between delegates
and events is as follows. Now we have already seen how you define a delegate in
the last sessions. Defining a delegate in delegate handles public delegate void, My delegate public
static, my delegate del. Calling a delegate
from another script, delegate handle dot del. The above code will run
without producing any error. This delegate handle domidel, where we are actually calling
the delegate by passing the reference of the script
will be executed in Unity. It will not produce any error defining an
event in delegate handle, Dotscript, public delegate void, my delegate public static
event, my delegate del. So we use an event keyword
basically to define an event, trying to call an event from another script,
delegate handle del. Now the above code will
produce an error and the error will be Delegate
handle del can only appear on the left hand
side of plus equals to or minus equals to y. Del cannot be passed directly
or used directly in another script when it
is an event basically. Okay, why to use events
along with delegates? Events provide security as they cannot be triggered
by other scripts. The logic in the game is not
exposed when we use events. Event makes it so that when a delegate is declared
as a part of class, it only exposes
the add and remove methods as per the access
modifier given to the event. Okay, let's say you have a magazine company
and people can subscribe to your company to receive new
magazine every month. You can think of that delegate
as the magazine company. And the event is
where people can subscribe to your magazine
or your magazine company. So whenever a new
edition comes out, the event will basically inform all the people already subscribe that a
new edition is out. And yes, you are ready
to get the magazine now. Okay. So that's it guys.
Thank you for the session. In the next session, we'll create an example for
events along with delegate. Thank you so much guys. I will see you in
the next session.
50. Move an UI Image to left & right using Delegate-Events: Hi friends, My name is Ron Sede. In this session, we
are going to create an example for
delegate with events. Okay, for that purpose we have created an image
here in the center, and then we have
two buttons here. Okay, we have also created
an empty game object, event object, and we have attached a script
delegate event here. Inside the delegate
event script, we are going to declare
delegate and events also for the image
here we have attached a script event script in
which we are going to write a code to move the image on
the left or on the right. Let's declare a delegate
first, delegate. This delegate is not
going to return anything. Okay, let's name the
delegate as delegate. Then let's declare an
event, public static. Okay, we declare an event
using an event keyword and then left delegate, left. Okay, then let's declare
another delegate. Delegate, right delegate. Let's declare another event, public static event,
right delegate. Now let's create
functions here to delegate separately on
function left delegate. And the other function will
call the right delegate, public left delegate. Inside this, we will
call left delegate. Okay, let's declare
another function here to call right delegate, public void, right delegate. Inside this function, we are
going to call the delegate. Okay, let's declare
two functions, public id, left. This is to move the
image to the left on the x axis. That's it. This code will move the
image to the right. Now let's subscribe
our functions here, move left and move
right to the events. To do that, let's pass a
reference to the script. Delegate event left plus equals to move left, okay? And delegate event right plus equals to move right. That's it. Let's say the script. Okay, let's go to
the left button here and click on
the plus icon here. Okay, let's track and drop
the event object here. Okay? And let's attach the function to delegate
event here, okay? And attach left
delegate function here. Okay? Now, same way. Go to the right button here, click on plus sign here, drag and drop event object here. And then go to Delegate
Event function. And select run, right? Delegate here. Okay, so that's
it. Let's run the scene. And let's see the output here. Okay, let's click on
the Moo, left button. Okay, the image is
moving to the left. Let's click on the right button. The image is moving
to the right. So that's it guys. Thank
you for the session. I will see you in
the next session. Thank you so much guys.
51. Introduction to Unity Input System: My friends, my
name is Rohan Sev. In this session, we
are going to learn about input system in Unity. What is an input system? The input system implements a system to use any
kind of input device. It could be your mouse, it could be your keyboard, et cetera, to control
your Unity content. The input system
comprises of two parts, input class and Input Manager. Methods from the input class are used to implement
inputs in a game. Input Manager specifies
the project settings, where buttons access inputs. Key presses and
mouse clicks can be assigned from real devices
to virtual inputs. This input manager can be found in Edit Project
Settings Input Manager. This is how an input
manager would look like. Okay, as stated earlier, input system in Unity can implement any kind of
input device, basically. Let's see them one by one. Keyboard inputs. The
input system can be used to implement or
detect keyboard inputs. We can get input from different operations
performed on the keyboard. Some of these operations are
as follows. Key press down. Key press down is triggered. Basically, when you press any
key input dot get key down. Function is triggered here and inside the function
in the brackets, we need to specify the
key key code dot space here is used to identify
space button on the keyboard, there are various such values, Unity to accept keyboard
inputs Hold key pressed, hold key pressed is triggered when you press
the key and hold it. Basically input dot
get key function is triggered when you keep
the key press, okay? Inside input dot
get key function, you need to specify
the key again. Key released is triggered when you press the key
and you release it. Input dot get key
triggered when you release the key after pressing it and inside the brackets. Again, we need to specify
the key mouse inputs. The input system can be used to implement or detect
mouse inputs as well. We can get input from mouse clicks and operations
performed on the mouse. Some of these operations
are as follows. Mouse button clicked. Mouse button clicked again, is triggered when you
click the mouse button. Okay, input dot get mouse button down is the function
triggered here. And zero here is the
left mouse button. Similarly, one is for the right mouse button and two is for the
middle mouse button. Mouse button hold, input dot get mouse button is triggered when you keep
the mouse button click, mouse button released
is triggered. When you click the mouse
button and you release it, input dot get mouse button up is triggered when you do so. Okay, let's go on
to the axis inputs. Now an axis refers
to a value between -1.1 with zero being
a default value. Analog stick provides values on both vertical and
horizontal axis between -1.1 Same goes for the keyboard, where left and right arrow
keys are the horizontal axis, and up and down arrow keys are the vertical axis,
horizontal axis. Input dot get axis. Horizontal is used basically to define the moment on
the horizontal axis. And for the vertical axis, we use input dot
get axis vertical. That's it guys. Thank
you for the session. I will see you in
the next session. In the next session, we'll see an example on how to
implement keyboard inputs. Immunity. Thank
you so much, guys.
52. Understand & implement Keyboard inputs in Unity: Hi friends, my name is Roan Sev. In this session, we
are going to implement keyboard inputs in Unity. Okay, for that purpose, we have already created
an empty game object, input system object here. And we have also
created a script. And the name of the script
is keyboard inputs. We have attached a script
to the empty game object, which is input system object. Let's write a piece of code
inside keyboard input script. Inside the script,
we need to implement all the keyboard inputs inside the update function in Unity. Firstly, we need to
check what kind of operation is being
performed on the keyboard. These operations would
be your key pressed, key pressed continuously,
and lastly, it would be your key released. Okay, To do so, to begin with, let's check with
an if condition, whether the key has
been pressed or not. Okay? Let's declare
an if condition here. Input get key down
inside the bracket. Here we need to specify the key. In this case we are going to use a space key here on
the keyboard, okay? Key code space. This is basically for the space bar on
the keyboard, okay? And inside this, let's print
something in the console. Let's print key has been pressed, okay? Input dot get key down function. We'll check whether
the space key on the keyboard has
been pressed or not. Let's implement whether the key has been pressed
continuously or not. Okay, let's write another
condition for that. Input dot get key, key code space. Let's print something inside dysfunction as
well continuously. Lastly, let's check if the pressed key has
been released or not. To do so, let's write
if condition here, input get keyed up. Okay? And let's specify the key, key space, whether the space key has been released or not
after it is pressed. Okay, let's print released. Let's add two more functions here to check whether
the player has pressed on the left arrow key and the right
arrow key as well. Okay, let's write one
more condition here. To do so, input dot get key down key code do left arrow inside this, we will print press Okay. And to check whether the player has pressed on the
right arrow key or not, let's supply one
more condition here. If input do get key down key code right arrow, let's print the right arrow key pressed. Okay. Firstly, I am just
going to press the Spacebar key on
my keyboard here. And let's check what
is the output here. Okay, so the key
has been pressed, key has been pressed
continuously. This is when I kept the key, basically
pressed continuously. And lastly, key
has been released, so this is when I released
the space bar key. Okay, so let's try with
left and right arrow keys. I'm going to press my
left arrow key now. Okay, So left arrow
key pressed again. Left arrow key pressed. I'm going to press
my right arrow key now on the keyboard. Okay, Right arrow
key pressed again. Right arrow key pressed. So that's it guys, Thank you
so much for the session. In the next session, we
are going to have a look at the mouse inputs in Unity. Thank you so much, guys.
53. Understand & implement Mouse inputs in Unity: Hi Franz. My name is Rohan Sev. In this session we are going to implement mouse input, unity. For that purpose, we
have already created an empty game object
input system object. Here we have also created
a script mouse input. And we have attached
the script to the empty game object
input system object. Let's open the script, and let's write a piece of code. To implement mouse
inputs in Unity, we need to implement
mouse inputs inside the update function. The way we did for
keyboard inputs, we need to check
for the operations performed on the mouse. These operations would be mouse button clicked
for the first time, then mouse button
clicked continuously. Then lastly, mouse button
released after being pressed. Let's check whether
the mouse button has been clicked or not. To do so, let's write
a condition here. Input do get mouse button
down inside the bracket. Here we need to specify
which mouse button, whether it is a
left mouse button, whether it is a
right mouse button or it is a middle mouse button. Okay, zero is for the
left mouse button, one is for the
right mouse button, and two is for the
middle mouse button. Okay, so let's print
something inside this. Let's write one more condition, or let's use a function in
pot get mouse button to check whether the mouse button has been pressed
continuously or not. Okay? So if input
get mouse button, let's put zero
inside this, okay? And let's print something
inside this continuously. Okay? Lastly, let's
check whether the mouse button has been released or not
after pressing it. Okay? If input get
mouse button up, let's add zero again inside this for the left mouse button, then let's print
mouse dot release. Okay. Okay guys, So I'm going to click the
left mouse button here. So yes, mouse button
clicked for the first time, then mouse button
press continuously. This is when I kept the mouse button clicked and
I did not release it here. So it kept on printing
mouse button pressed continuously until I
released the mouse button. Lastly, here. So that's it guys. Thank you for the
session. I will see you in the next session. In the next session, we'll implement access
inputs in Unity. Thank you so much guys.
54. Understand & implement Axis inputs in Unity: Hi friends, my
name is Rohan Dev. In this session, we are going to learn access inputs in Unity. Access inputs will refer to
horizontal and vertical axis, and the value will range from minus one to one in
floating points. Okay, for this purpose, we have already created
input system object, which is an empty game object. And we have also created
a script access inputs. And we have already
attached the script access inputs to the empty game object input system object. Let's write a piece of
code inside access input. Script axis inputs refer to the values or
the floating values between -1.1 both on the
horizontal and vertical axis. An analog stick
provides values for horizontal and
vertical axis between -1.1 Same goes for the keyboard. The horizontal axis will be your left and right arrow keys, and the vertical axis will be your up and down arrow
keys for the keyboard. Float, float vertical. Okay? Inside the update function, let's assign value to
the variable horizontal. And that value will be input, do get axis horizontal, horizontal equals to input, do get axis horizontal. Inside the double
vertical will be your input get axis vertical, horizontal greater than zero
on the horizontal axis. If the value is
greater than zero, it means that the player has pressed on the
right arrow key. Okay, let's print the
value for horizontal also. Let's print right right turn. Let's apply an else
condition here, L horizontal lesser than zero. This simply means that
the player is pressing on the left arrow Key,
print horizontal. Let's print left turn
inside this left turn. This is for the horizontal axis. Let's apply a few conditions
for the vertical axis, vatical greater than zero. This will check if the player has pressed on the arrow key. If the player presses
on the arrow key, the value of Tic will
be greater than zero. And if the player presses
on the down arrowkey, the value for Vatical
will be less than zero. Let's bring the
value for vertical. Let's apply an L condition for this Tic less than zero. Okay guys, on my keyboard, I'm going to press my
left arrow key and print the value for
horizontal axis. Okay, so let's scroll this down. Okay, It's left turn and
it's showing minus one here. Okay, so I'm going to
press my right arrow key. Now the value for
horizontal axis is one. And it's printing
right turn here. I'm going to press
my up arrow key. Now the value for the vertical axis is one
here and it's printing up. Okay, I'm going to press
my down arrow key. Now the value for vertical
axis is minus one now, and it's printing down here. Okay, So that's it guys. Thank you for the session. I will see you in
the next session. Thank you so much guys.
55. Introduction to Physics Engine & Rigidbody: Friends. My name
is Rohan Vasudev. In this session, we'll
be talking about physics and frigid
body in Unity. Physics in Unity is handled by Built In Physics Engine.
Unity is built in. Physics Engine runs the physics for game object interactions and various effects such as gravity acceleration,
collisions, et cetera. Unity simulates
physics to ensure that the objects correctly accelerate and respond to the collisions, gravity, and various
other forces. To have convincing
physical behavior, an object in a game must accelerate correctly and
be affected by collisions, gravity, and other forces. Unities built in Physics Engine provide components that handle the physical simulation
for you that behave passively in
a realistic way. There are two separate
physics engines in Unity, one for Thredyphysics and
one for two D physics. The main concepts are identical
between the two engines, but their implementation
is different. For example, there is
rigid body component for Thrediphysics and
rigid two D component for two D physics. Let's talk about
rigid body immunity. Now, Rigid body immunity allows a game object to
have physical behavior. It will interact with
other game objects. The Unity physics
engine only knows that an object is meant
to be acted on by the physics if the
rigid body component is attached to the game object. Properties of a rigid
body mass, drag, angular use, Gravity is
nematic interpolate, collision detection
and constraints. Let's see one by one, what does these properties mean? Let's talk about mass here. Mass is the mass of
the game object. Drag is the air resistance value applied to the game
object. Angular drag. Angular drag is the
air resistance value affecting the rotation of
the object is kinematic. If enabled, object
will not be affected by physics engine in
Unity interpolate. It is used to smoothen the moment of the object
collision detection. It changes the type of collision
detection on the object, constant freezes, moment and rotation on certain axis
of the game object. That's it guys. Thank
you for the session. I will see you in
the next session. Thank you so much, guys.
56. Applying Rigidbody to the Sphere gameobject: Hi friends, My
name is Rohan Sud. In this session we are going to create an example
for Rigid Body. For the demonstration purpose
we are going to create a three D game object which
is going to be sphere. And we're going to
apply rigid body to the sphere basically. Okay, so let's start
with creating a floor which will be a three D
game object which is plane. For that purpose,
go to game object, go to three D object
and select plate here. Okay? Right now, the plane is
not visible on the camera. To do that, just reset the
transform value for the plane. Okay, and yes, it is
visible in the camera. Again, let's create a three D game object,
which is sphere. Go to game object, go to three D object
and select Sphere here. Again, reset the transform
for the sphere here. Okay, go to scene mode here and slightly bring the
sphere above the ground. Okay, this is how
it should look. The sphere basically stays
floating in the air. Right now, we have not applied any rigid body to the sphere. Let's stop running the scene, and let's apply the rigid
body to the sphere. Now, click on Ad Component, go to Rigid Body here, and yes, the rigid body component is attached to the sphere
game object here. Let's run the scene again, and let's see the output here. Okay, the sphere now
falls on the floor. Let's understand the properties for the rigid body one by one. Okay, let's stop
running the scene here. Mass here basically is
the mass for the sphere. It is right now set to one. Drag is the air resistance value applied to the
sphere game object. Angular drag is the air
resistance value, again, applied to the game object that will affect the
rotation of the sphere. Okay, use gravity. Here is the gravitational force applied to the
sphere game object. If we check the
checkbox here or if we check the Use gravity
to true here, that means that the
gravitational force is applied here to the
sphere game object. Let's uncheck the Use Gravity here and let's run
the scene again. Since we have said the
use gravity property here to falls now it does
not fall on the floor. Let's set the use gravity
property to true again. And the sphere will fall
on the plan game object. Okay, let's stop running the scene again is
kinematic property. Here basically will
define whether the physics engine will affect
the game object or not. Let's set it to true here
and let's run the scene again by setting is
nematic to true here. The spear basically is not affected by the physics
engine anymore. Okay, let's uncheck the property and the sphere will
fall on the floor. Again, collision detection is basically the type
of detection okay, that will act upon
on the sphere. There are four options,
Discrete, continuous, continuous, dynamic, and
continuous, speculative. Then we have interpolate. Interpolate. It smoothens the
moment of the game object. Right now, it is set to none. We have two options here,
interpolate and extrapolate. We will understand this
or we'll learn more about this in the
upcoming sessions. Okay, constraints property
here is basically used to freeze the position or rotation
of the game object on x, y, or z axis. Let's check y axis here, and let's see if the sphere
falls on the floor or not. Okay, the sphere does
not fall on the floor, it is again floating in the air. Let's uncheck the y axis here, and yes, the sphere falls
again on the floor. So this is how rigid body works on any three D game object. So that's it guys. Thank
you for the session. In the next session
we'll see an example on how to move the sphere using
a rigid body component. Thank you so much guys. I'll see you in the next
session. Thank you so much.
57. Applying Material to the Sphere gameobject: Hi friends, My name
is Rohan Vasudev. In the last session, we applied rigid body component
to the sphere. In this session, we
are going to move the sphere using rigid body
component inside the script. This session is going to
be a three part session. In the first session,
we are going to create a texture and apply the
texture on the sphere. Basically, we are
going to create a material. What is a material? Material specifies the
optical properties of the game object. For example, it's color, whether it is dull or
whether it is shiny. Texture is basically
an image which is a layover or wrap
around the game object, which again provide
the visual effects for the game object. Okay, so to start with, let's create a folder
here and let's create a Material to create a folder, right click here inside the
Assets folder to create. And click on folder here, rename the folder to Materials. Materials. Okay? Open
the Material folder, right click here inside
the Material folder again, and select Material
to create a material. Okay? Name the material as
beach ball or the name, could be anything
of your choice. Okay, we have created a
material here for the ball. We need to apply the
texture here for the ball. Now, texture is basically,
as I stated earlier, is an image, so we need to download an image
from the Internet. What we'll do here
is we'll apply a beach ball texture here
to our ball basically. Okay, Just click on
the color map here. Okay? And just right click
here and save images. Okay, Images. Okay, so your image has
been downloaded now. Just click on Showing the
folder, open your Unity, Go to the folder here, and just drag and drop the image here inside
the Material folder. Okay, that's it. Select
the Material again. Okay, Click on Albedo here, okay, And just select
Beach Ball Color. We have applied the texture
here to the material. We need to apply this material
to our sphere game object. Just click on the sphere
game object here. And inside the inspector window, just drag and drop
the material here for the spear game object.
Okay, and that's it. We can see here
material has been applied or the texture has
been applied to the ball here. So that's it guys, thank
you for the session. In the next session, we will be creating a floor for
the ball to move. Thank you so much guys. I will see you in
the next session.
58. Create a floor for the Sphere to move: Friends, My name
is Rohan Vasuev. In the last session we
applied texture to the ball. In this session we are
going to create a floor. We have already created a
material for the floor here. Okay. And also we
have downloaded texture for the floor
from the Internet. Okay, let's apply this material to the plane game object here. In this case, plain is
going to be our floor. We're going to have
multiple plain game objects to create one big floor. Before creating multiple
plain game objects, we need to create an
empty game object and name it as Floor. That will be the parent game
object for all our plain game objects because we need to keep
everything organized. Okay, let's right click here on the scene and create
empty game object. Rename the empty game
object here to floor, okay? And just track the plain object inside the floor game object. Okay, now we need
to replicate plane here multiple times to
create one big floor. To do that, just select
Plan Game Object and click on control D and it will
replicate the game object. Now we need to adjust the plane, one game object here. To do that basically we
need to keep the move tool selected here in the
editor and just drag this. Okay? Does it look fine? Yes, it looks good.
Yes, it looks good. Okay, again. Now click on plane
one game object here, and click on Control D. Here
we have created our floor. Okay, let's go to game mode
and let's see how it looks. Let's bring the camera on the top to give
it a better view. Thank you so much, guys. Thank you for the session. In the next session,
we're going to move the ball using a
rigid body component. Thank you so much, guys. I will see you in
the next session.
59. Move the Sphere using Rigidbody attached to it: Hi friends. My
name is Rohan Sev. In this session, we are
going to move the sphere using rigid body component
attached to the sphere. For the demonstration purpose, we have already created a rigid body move and we have attached a script to the
sphere game object here. Now to move the sphere, we will have to declare
a few variables here. Okay, float variable,
vertical, float variable, horizontal A, float speed equals to five. And rigid body R B. Okay? This rigid body R B is basically used to get the rigid body component
from the sphere. To get the rigid body component, we will have to use get
component function in Unity. Okay? We will have to initialize the rigid body variable using
get component function, component, rigid body, okay? Inside the update function. We have already seen this
in the previous sessions. How do we use input
dot get axis? In this session we are
going to implement input. Do get access to move
the sphere basically, but to move the sphere again, we are going to use a rigid
body component of the sphere. Now inside the update
function equals to horizontal, equals
to horizontal. Okay, let's apply L's
conditions here inside the update function
to check whether we are pressing on
the up arrow key, whether we are pressing
on the down arrow key, whether we are pressing
on the left arrow key, or we are pressing on
the right arrow key. To do so, let's apply the first condition here
for the vertical axis. If vertical greater than zero, RB a force vector three forward into speed. Let's apply another
if condition. If vertical lesser than zero. Okay, so let's apply force
to the rigid body again at force vector three back into speed. Now let's apply conditions for the horizontal axis to check whether the player
has pressed on the left arrow key or
the right arrow key. Okay? To do so, if horizontal greater than zero, this condition will be for
the right arrow key. Okay? R B a force vector three right into speed. And lastly, horizontal
smaller than zero, R B, add force vector three left into speed, okay? So the ball is moving now. We can increase the speed, or we can decrease
the speed, okay? So for that purpose
we will have to declare two more variables here. Public game object,
camera, okay? And then let's declare one
more variable of vector three. Let's name the
variable as offset. This variable will be
the distance, basically, that we're going to
calculate between the camera and the
sphere game object. Okay, let's assign some value here to the offset
variable, okay? The start of the scene offset equals to n vector three. Camera transform position x. Camera trans form position y plus one. Okay? We want to keep the camera basically slightly
above on the y axis. And then camera dot transform, position s minus transform do position, transform do position is the
position of the sphere here. Okay, so now we have set
the value for offset. First condition here. If vertical greater than zero. Let's add one more
line of code here. Camera transform position equals to transform position is the position for
the sphere, okay? Plus your offset
plus the distance. We'll have to replicate
this code, okay? Basically, in all the
if conditions here. Lastly, we will have to specify an Ls condition
here as well. Wherein if the ball
is not moving, if the ball is not
moving, again, we have to specify
the same code. Camera transform plus offset. Okay, that's it.
Let's save the script here and let's go to the editor. Okay, Click on the
Sphere game object here. Just click on Made
Camera and just drag the object and just
place it here. That's it. Okay. Okay, so that's
it. That's it. We have our camera
following the sphere as well. So that's it guys. Thank you so much
for the session. I will see you in the next
session. Thank you so much.
60. Introduction to Colliders & Collisions in Unity: Hi friends. My name
is Rohan Masudev. In this session we are going
to talk about colliders, triggers, and
collisions in Unity. So what are colliders in Unity? Colliders are components
in Unity that provide collision detection
between the game objects. They define the shape of game object for the purpose
of physical collision. There must also be one
rigid body attached to one of the game objects
to detect collisions. Colliders allow you to listen to and respond to collisions. Colliders can be of many types, but mainly there are two types, two de collider and
three collider. For two game objects to
de colliders are used. And for three game objects, three D colliders are used. Let's talk about Box collider three D. Now when you create any three game object in Unity three D collider is
attached to it by default, which is indicated by green border lines
around the game object. In the image here,
we can see we have created a three game
object which is cubes. The green line surrounding here, the cube game object
basically is the collider. This collider can be manipulated to be larger or
smaller than the box, depending on the
objective of your game, how you want Unity's colliders to interact with each other, utilizing Unity's
physics engine. Let's talk about
collision triggers. Now when two game objects
collide with each other, Unity provides events
that are called. There are mainly two
types of events, collision trigger events
and collision events. Collision triggers are used
mainly when we want to trigger some events
that should be ignored by the physics engine. When two objects collide, they will pass
through each other, but some events will be fired. At least one of them must have a rigid body component
attached to it. Trigger events can be
achieved by setting the trigger option to be true
in the collider component. Once we set it to be true, it will be ignored by the physics engine and
can be used to trigger events when the game object collides with
another game object. There are three events
for collision triggers and they are as follows
on Trigger Enter. On Trigger Enter is called when one collider comes in
contact with other. With one of the colliders having trigger enabled
called only once. Then we have on trigger stay. On trigger stay is
called frame when there is contact between
collider and the trigger, it is called multiple
times until there is contact between
the two colliders. On trigger exit,
on trigger exit is called once the collider
stops touching the trigger. Called only once. Okay, let's talk
about collisions. Now a collision in
Unity happens when two game objects with colliders attached
interact with each other. They may touch each other, stay in contact with each other, or may stop colliding. At least one of them must have
a rigid body component for the physics engine to
recognize them as colliders. There are three
events for collision. They are as follows
on Collision Enter, called when one collider
comes in contact with another collider
called only once on collision stay call for every frame when there is
contact between colliders called multiple
times until there is contact on collision exit called once the collider stops touching another collider called only on. Let's see the difference
between trigger and collision. Trigger invoked by event system when two game objects
overlap each other, collision is invoked
by physics engine. When two game objects
collide with each other. Collision information is shared through the trigger events, which is on trigger enter, on trigger stay and on trigger exit collision
information is shared to the collision events which
is on collision enter, on collision stay and
on collision exit. Trigger property in collider
component is enabled. Trigger property here in collider component is
disabled for collision. Trigger is used to sense the presence of
other game objects. Collision is used to physically interact with other
game objects. That's it guys. I will see
you in the next session. Thank you so much guys.
61. Adding 3D Cube gameobjects on the floor & add Tags to them: Friends. My name is Roan Suev. In this session we
are going to create an example for
collision detections. We are going to create some
obstacles in the path here. These obstacles will
be cube game objects. Basically, to begin with, let's create an empty
game object here. Okay? Create empty and rename the
game object to obstacles. Now inside the obstacles object, we're going to
create some cubes. To do so, right click here on the obstacles and go to
three D object here. And click on Q. As we all can see here, when we create a
cube game object, box collider is attached
to it by default. Let's add a rigid body as
well to the cube here. Okay, let's increase
the mass for the cube game
object to ten here. Let's just drag and drop one
material on the cube here. Scale the size of the
cube game object a bit. It's looking too small in size. Let's keep it to 1.5 Okay, let's bring it up a little bit. The game object is
already selected here. Just click on control
D to replicate the game objects so that we
can create more obstacles. On the way for the sphere, we have created the obstacles, we have created
123456 obstacles. On the way for the Sphere tag is basically to identify the
game object through script, select game object here, and go to Tags here, and click on a T. Okay? Click on the plus sign here
and add a new tag name. Keep it as one. Okay? Add one more tag name. Keep it as cube two. Cube two, save. All right, so we have
created two tags, cube one and cube two. Again, select on cube here
for the tags it is tagged. Right now, just
click on the drop down and select cube one here. Then go to cube one here and
select one here for this. Okay, basically for
the white cubes, we are going to
select one as a tag. For the black
cubes, we are going to select cube two as a tag. Okay, so let's run the scene. And let's move the ball. Okay, let's move
the sphere here. Right now the sphere is colliding with the cube
game objects here. Okay, but since we have not added any collision
events inside the script, we are not performing
any actions on it. Basically, in the next
session we're going to use collision events inside the
script to detect collisions. And we are also going to use the tags we have
just created here. Okay guys, thank you so much. I'll see you in
the next session. Thank you so much, guys.
62. Detect Collision with the 3D Cube using Tags: Friends. My name is Ron Vase. In this session, we
are going to implement collision events inside
the Unity script. These collision events
are on collision Enter, on collision stay, and
on collision exit. Let's write a piece of code
inside the Unity script. Let's begin with On
collision Enter. Function on collision
enter will be called when two rigid bodies
collide with each other, or two colliders collide
with each other void. On collision Enter, let's
pass a collision class. Collision class holds
all the information, for example, impact, velocity, and contact points,
collision inside. On collision enter,
we are going to use tags that we created
in the last session. We had created two tags, cube one and cube two. Cube one tag for the white cubes and cube two tags was
for the black cubes. Basically, let's write at if codition inside on
collision enter function call object tag equals to equals to cube one. Basically if it is a white cube then we're going to
print something inside this debug log collision started with white que. Okay, this condition
is for the white que. Let's write an Elsif condition. Elf call game object
tag equals to, equals to two bad log collision started with cube. Okay? So let's write another function here which
is on collision stay. On collision stay function
is called once per frame. Okay, void on collision stay. Let's write an if
condition again. Here we stay black cube. Lastly, we're going to use
on collision exit function. On collision exit function
will be called when two Richard bodies or colliders stop colliding
with each other. Okay, so we have implemented all three functions here
on collision enter, on collision stay, and
on collision exit. So let's run the scene and let's see how this thing works. Let's collide with
the white cube here when the spear collided
with the white cube. We all can see here
collision started with white cube and then we
have collision stay with white cube since the spear
is still colliding with the On collision exit
has not been called yet. But once I move the Pal
away from the cube here. Okay, collision exited with
white cube will be called. So let's go and collide
with the black cube now. Okay, so this is the black cube. Okay, so collision
stay with black cube. Let's move the spear away from the black cube and let's
see what it prints. Okay, collision exited with
black. So that's it guys. Thank you for the session. I will see you in
the next session. Thank you so much guys.
63. Introduction to 2D & 3D Animations in Unity: Hi friends, My name
is Rohan Maze. In this session we're going to talk about Animations Unity. So what is animation's Unity? Unity's animation
system is based on the concept of
animation clips. Which contain
information about how certain objects should
change their position, rotation, or other
properties over time. These animation clips
are then organized into a structured flow chart like system called an
animator controller. The animator controller acts as a state machine which
keeps track of which clip should currently
be playing and when the animations should
change or blend together. A simple animator
controller might only contain one or two clips. For example, to control
a rotation or bounce. Or to animate a door opening and closing at the correct time. A more advanced
animator controller might contain dozens of humanoid animations for all the main characters
actions such as walking, running, shooting, et cetera. So this is how an animator
controller looks like. This animator controller
which has idle and walking animation clips is attached to the humanoid
character here. Okay, now let's talk about
animation state machine. What is animation state machine? Animation state machine keeps
track of which clip should currently be playing and when the animations should
change or blend together. It is common for a character or other animated game
object to have several different
animations that correspond to different actions it can
perform inside the game. A character may sway slightly while idle walk
when commanded to, and raise its arms in panic
as it falls from a platform. A door may have
animations for opening, closing, getting jammed,
and being broken open. Unity animation uses a
visual layout system similar to a flow chart to
represent a state machine. Which enables you to
control and sequence the animation clips
that you want to use on your character or
any other game object. What are state
machine transitions? State machine
transition simplifies large or complex state machines. Each view in the animator window has an entry and exit node, used during state
machine transitions. The entry node is used when transitioning into
a state machine. The entry node will be
evaluated and will branch to the destination state or to the animation clip according
to the conditions set. The exit node is used to indicate that a state
machine should exit. Now, in the image below, we can see the entry node is transitioning into the
idle animation here, Idle animation here
being the default state. The idle animation will then transition either
into walking or into the running animation clip
depending upon the condition set inside de animator
controller. That's it guys. Thank you for the session. I will see you in
the next session. In the next session we'll create an animation on a sprite. Thank you so much guys.
64. Slice a Spritesheet into multiple Sprites & apply walking animation: My friends, my
name is Rohan Sev. In this session, we
are going to create an animation on the sprite. Sprite is basically an image for the demonstration purpose. We have already created a
two project in Unity and we have also created a scene Sprite NM
inside the project. To begin with, we need to import sprite sheet in the project.
What is sprite sheet? Sprite sheet is basically multiple images in a
single image in a grid. This is how a sprite
sheet would look like. These are basically
multiple images packaged into one single image, and this is called
a sprite sheet. All right, let's begin with
downloading this image here. Now let's get the sprite sheet inside the Unity project here. But before doing
that, let's create a folder and name the
folder as sprite sheet. Okay, Click on Create here, and click on Folder Name
the folder as Sprite Sheet. Open the folder and just drag this inside
the sprite sheet folder. All right, so this
is one single image, now we need to slice it
into multiple images. So how do we do that?
Firstly, select the image. All right, In the
sprite mode here, select multiple, Okay,
And click on Apply here. And click on the
sprite editor here. This window will open up. All right, once you
get this window open, click on Slice
Slice option here. Click anywhere on the screen. And click on Apply,
Close the window. And yes, we have
multiple images here. Okay. As you all can see here, we have Sp star, single image into
multiple images now. All right, now we need to use all these multiple images
to create an animation. Since we have created multiple sprites out of
a single sprite sheet, we will select this
particular image. It's an ideal image for
the person walking. Just drag and drop
the person here. Let's scale the size
of the sprite here. Let's scale it to two x y axis. Okay? Perfect. Now select on the sprite here and
go to Animation tab. All right, so let's click on
Create to add an animation. Rename the animation
walking animation. All right, click on Save here. Let's drag the Animation
tab here somewhere. Extend this. What do we do next? We need to select all the sprites here, apart from the original
sprite which is already there inside the scene. Okay, Click on control
button here and keep on selecting all the
other sprites or all other animations
which we want to add. Again, it depends on what
kind of animation it is. Maybe we want to use
just four sprites, then just select four sprites. If we want to use
all the sprites, then select all the sprites. All right, I need
all the sprites, so I'm selecting all
the sprites here, okay? Just drag and drop all
the sprites here, okay? Again, get the tab here
to be more comfortable. All right, let's see how the animation looks
Now, it's too fast. What do we do here?
Okay, scroll your mouse and okay, minimize this thing. Okay. To make it a little slow, just increase this to, I think 50 is fine here. Yeah, just try the
animation again. I think it's perfect
now. It's looking good. Let's stop this, save the scene, let's run the scene here, and let's see the output.
All right, perfect. We have our sprite walking here. That is how we do animations. Thank you so much guys.
Thank you for the session. In the next session,
we are going to create a background image or the
background for the scene here. And also we're going to move this sprite to left or to right, depending on what arrow keys
you're pressing down there. All right. So thank
you so much guys. I'll see you in the next
session. Thank you so much.
65. Add background to the Scene: Friends, My name
is Rohan Masudev. In the last session we created an animation on the sprite here. We created a walking animation
clip here for the sprite. All right, when we did that, this animator
controller was created. Right now, we have applied only one
walking animation clip to this particular
animator controller right here in this session, we are going to apply a background image here
for this particular scene. Before that we need to
have a background image. Either you can
create it or you can download it from the web. I'm going to download this image and apply it as a
background for the C. I've already downloaded
this image here. Let's get this image
into our project. Just track this image here. We have imported the image
here inside our project. Now the next step would be to create an empty game object, which will serve as a
background image basically. All right, right click
here on the scene and go to Game Object and click Create Empty
here. All right. Rename the game object
to background, okay? And just drag and
drop this image on the background empty
game object here. All right, Right now the image is not looking good at all. We need to adjust the scale
for the image basically. All right, let's keep it to, let's say 0.3 on x axis, 0.3 on y axis, and 0.3 on the said axis. Click on the scene tab here. Now this image is not enough. We want to create a
huge scene here because we're going to walk eventually
using control keys. All right, what to do
next is just choose the image here inside the
background empty game object, and click on control
D. All right. Now select the move
tool here and just move the image, okay? And again, click on
this particular image, which is right in the center. Again, click on control D.
With the help of move tool, just move the image here. All right, now the sprite is up in the air and
it's flying in the air. We need to make it look
like it's on the ground. What to do next is just select your sprite in the sea
and just bring it down. Okay, let's go to the sea now. And looks fine
now. Looks better. Let's click on the
play button here, and let's see how it looks. All right, it's looking good. The animation is being
played and we have a background image as
well set for our scene. Currently, if you see here, in spite of playing
the animation or applying the
animation on the sprite, currently the sprite is not moving forward in the
forward direction. Okay, in the next
session we are going to apply the script
to the sprite. Basically to move
the sprite in the forward and in the
backward direction. Again, we'll create an animation which will be an idle animation. If you are not
pressing any keys, then sprite should stay idle and should
stop walking here. All right guys, Thank
you for the session. I will see you in
the next session. Thank you so much guys.
66. Move the animated Sprite using keyboard inputs: Friends, My name is Rowan Suv. In the last session we
animated the sprite. In this session we
are going to move the sprite using
Unity C sharp script. Okay, for that purpose, let's create a folder
here called scripts. Open the scripts folder here, and let's write a C sharp script inside the scripts folder. Sprite is the name
of the script. Let's write a piece of code inside the move sprite script. Okay, let's declare a
float variable here, float horizontal. We're going to
move the sprite on the horizontal axis,
float horizontal. All right, let's remove
the start method. We don't need a start function here inside the update function. Let's assign a value to the
horizontal float variable, which will be your input axis, horizontal. Okay, let's apply a
condition to check if the sprite is moving in the right direction or
the left direction. To check if the sprite is
moving in the right direction, let's apply a condition if
horizontal greater than zero. All right, inside this, let's use get component. And inside get component, we are going to get
Sprite Renderer, which is by default
attached to the sprite. So when we create a sprite, sprite renderer component
is attached to it. So we are getting Sprite
Renderer component, okay, Sprite Renderer component, flip X equals to falls, Okay, flip X basically will flip
the sprite on the x axis. Over here, we want to
keep the sprite as it is. We don't want to flip it when the sprite is moving in
the right direction. So we're going to keep
it to falls again, let's declare a vector three, variable vector three moment equals to n vector three. Okay? On the x axis, I want to apply 1.5 0.0 okay? Into equals to time delta time. All right, we're going
to move the sprite using transform
translate function. Transform translate
and insight translate. We're going to add
movement very. Okay, so let's apply another condition which is
horizontal less than zero. If get component sprite render a flip x equals to true when the sprite is
moving in the left direction, we are going to flip the
sprite on the x axis. Basically vector three moment equals to n, vector three -1.5 on the x axis, zero on the y axis, and zero on the z axis. All right, again, movement into equals to t delta time. Lastly, changing the position or transform for the
sprite Using transform, translate function in Unity translate and inside translate, we're going to add moment here. Okay, let's save the
script and let's attach the script
to the sprite here. Let's just drag and drop
the script on the sprite. The script is attached
here to the sprite. Now let's run the game, and let's see how it works. All right, let's press the right arrow key
on the keyboard, and the sprite starts moving
in the right direction. Let's press the left arrow
key on the keyboard, and the sprite starts moving
in the left direction. It works fine, but there
is a problem here. Even if I stop pressing
the arrow keys, we all can see here the
animation is not stopping here. Okay, the animation goes on. So in the next session,
what we'll be doing, we'll be applying
another animation to the sprite basically, which will be an idle animation. So once I release the
keys on the keyboard, all right, idle animation
will be played. And once I again
press on the keys, the walking animation
will be played again. So thank you so much.
That's it guys. I will see you in
the next session. Thank you so much guys.
67. Apply idle animation to the Sprite & make Camera follow the Sprite: Hi friends. My name
is Rohan Vasudev. In the last session, we
moved the sprite using transformed or translate
function in Unity. In this session, we are going
to apply idle animation to the sprite so that when we stop pressing on the left or
the right arrow key, the idle animation
will be played and the walking animation
will be stopped playing. All right, so to do that, let's start with creating an idle animation
for the sprite here. Select the sprite
here in the scene. Go to Animation tab and
click on the drop down here. And create a new
clip for the sprite. Okay, just click Create
new clip here. All right. Now inside any folder or
the sprite sheet folder, we can create a new
animation clip. Name the clip as idle animation. Okay, save the script. Bring the animation tab here. Click on the sprite sheet here, and drag the first sprite here, which is an idle
animation sprite. Basically, this
is an idle sprite which will be used
for idle animation. Again, bring the
animation tab here. Just click on the play button. Okay, it's not doing anything because it's an idle animation. When we stop pressing on the
left or the right arrow key, this animation will be played. We have two animations here. One is the walking animation. Another is the idle animation. All right, over here, the default animation
is walking animation. If we hit the play button, then the starting animation
will be a walking animation. Let's change it to
idle animation. Okay? Because that should
be the entry point. All right, so let's go
to animator tab again. Click on idle animation here and click on Set
as default state. This will be the
default state once we start on the Play
button in the game. Let's create some transitions. Basically, when we
hit the Play button, this animation is
played as it is set as a default animation now. But when we click on the
left or the right arrow key, walking animation
will be played. To do so, just right click
on the idle animation. Click on transition to
walking animation. All right. Similarly right click on
the walking animation. Make transition and then bring it down to
the idle animation. Just click on the arrow
here, deselect this. Click on the settings here. And transition duration
make it to zero because we don't want
to set any duration. Transition duration is basically the duration for the transition between the two animations. Okay, Again, click on this arrow and check
this has exit time. And set the transition
duration here to zero again. All right, now we need to set some conditions to check whether the player is pressing
on the arrow keys or not pressing on
the arrow keys. Okay, so do so. We need to
create a parameter here. Let's create a new parameter by pressing on the
plus button here. Now there are four types of parameters that we can create. We are going to create here a bool data type of parameter. Okay, Let's give it
a name, Can walk. This is the name
of the parameter. Again, click here
on the arrow, okay? And set the condition here. If can walk is true, then walking animation
will be played. And if can walk is false, then idle animation
will be played. Let's set one condition
here. Can walk true. This simply means if
can walk is true, walking animation
will be played, okay? Click on the arrow here, again, again, set
a condition, okay? If can walk is false, then idle animation
will be played. Now we need to call the animator which is attached to the sprite. So to do so, let's declare an animator
here, animator name. Okay, We don't have a
start function here. Let's add start function. We need to initialize
the animator. All right. As soon as the game
start any equals to get component animator. All right, now inside this we need to set the
poll which is can walk to true if we
press on the arrow key. To do so, anim dot set pool, the name of the parameter can walk and set it to true here. Okay, Again, inside
this condition, again we need to set
the ball to true. Set B can walk to true. All right, let's declare
an L's condition here. So if the player is not walking or the
character is not walking, let's set the anim set. Bull can walk to falls again. Can walk falls. All right, let's save the script here. Everything is set here. Let's run the game. And
let's see the output. Right now, I'm not pressing
on the arrow keys here, the idle animation
is being played. Let's click on, or let's press on the
right arrow key here. And the walking animation
starts playing. All right, the moment
I release the key, idle animation is
being played again. Let's move to left again. Okay, the walking
animation starts. Let me release the
arrow key here. All right, we'll make the main camera follow
the character here. So it's very simple to do. So let's select Main
Camera here and make it the child object for the sprite game object
here or the sprite here. Okay, so just drag it and
put it inside your sprite. All right, let's play
the scene again. All right, so the camera is
following the player as well. Okay, it stops. Okay, here we go. Looking good. All right, so that's it.
Thank you so much guys. I will see you in
the next session. Thank you so much guys.
68. Import 3D Character in Unity & apply walking animation: Hi friends. My name
is Rohan Vasudev. In this session, we
are going to create a animation for three
D character here. This three D character,
we are going to download from our website, which is Mixamo.com by Adobe. Also the animation for
this particular character, we are going to
download from Mixamo. All right, so let's go
to the website and let's start downloading the character and the animation for the same. Here we are on
Mixamo.com All right, You can choose any of
the characters here. Okay, I'm going to choose
this character here. Let's click on the
download button here. Post should be Post. We have downloaded the
character from Mixamo. Now let's go and get the character inside the
three D characters folder, which we have created
inside the Assets folder. Let's just drag
and drop it here. Before putting the
character inside the scene, let's create a floor for
the character to walk on. All right, let's
go to Game object, go to three D object and
let's create a plane here. Okay, plane is not visible. Just go to transform
here and click on Reset. All right, that's good. Okay, let's create another plane here so that we can
have a bigger flow. And let's suggest the thing, okay, so we have a
bigger flow now. All right, let's try getting this character inside our scene, such as drag and drop it here. Okay, so we have our character
inside the scene now, but we can see, all right, there are no materials or
textures on the character. To apply textures
on the character, what we need to
do is just select the character here, okay. And click on Materials, and click Use
External Materials, Legacy, and click Apply. And the material
should be applied. Now to the character. We can see the materials or the textures applied
to the character. Now the way it was on Amo.com click on the Rig tab
here, Animation type. This is a humanoid character, so need to select Humanoid here. And click on the
Apply button here. Now next go to Animation here and check Look Time here, okay? And click on Apply here, but there is no
animation applied to it. To apply the animation, let's again go to Amo.com and click on the
animation tab here. And we want to walking. Animation, Search for walking. Okay, let's select this. Animation Perfect. Perfect. Mutant walking is the name of the animation
clip which we are going to apply on our
character while walking. Okay, Click on download here. Format BX for Unity is fine. All right, and this
should be without Sky. Click on the download
button here. All right, let's get this
animation clip inside our three D characters folder again by just dragging
and dropping it here. Let's select this which
is an animation clip. Okay, go to rig here and again animation type to humanoid
create from this model. And click on Apply button here. Go to Animation tab Again, check on Loop time,
begin to pose. Check this based upon
body orientation. And click on Apply here. Again, select my character here. Now what we need to do is we need to create an
animator controller. Okay, So go to Create here and click on animator controller. Okay, My controller name the animator controller
to my controller. Just open the animator
controller and let's just track this walking clip here inside the
animator controller. All right, now let's
go to my character again here and apply this animator controller
for the character. Let's run the scene here. Yes, the character is walking. Let's get the character a
bit behind in a camera view. Okay? All right, the
character is walking, but we want our character to
move with the arrow keys. In the next session, we're
going to apply the script to the character along with
character controller. That's it guys. Thank
you for the session. I will see you in
the next session. Thank you so much guys.
69. Move the 3D Character using keyboard inputs: Friends, My name
is Rohan Masrev. In the last session we applied animation to this character. In this session, we are going to make the character walk in the forward direction when we press on the arrow
keys on the keyboard. Let's select my character
here and uncheck. Apply root motion. Basically, since we
are going to move this character using arrow keys, we will uncheck this. Apply root motion here. Then we need to modify
the walking animation, which we apply to
the character here. Okay, let's run the scene and let's see the
difference here. Let's see how the
animation looks. Now we have unchecked the
applied root motion now. All right, so the character
walks at one place. It's not moving forward
because we are going to move the character using
the arrow keys now. Now let's scroll
down here and go to root transform position y for the walking animation clip. This is the walking
animation clip which we applied
on the character. Okay? For the root
transform position Y based upon chains are
based upon two feet. Okay? And click on
apply here, Perfect. This is the animation
that we want in our cave. Here we are on Mamo.com
I've already searched for the idle animation
and I am going to apply this unnamed idle
animation for our character. Okay, This is how our character is going
to look when it's idle, when it's not walking. Let's download the clip here. Vx for Unity BX. All right, and without skin, let's click on the
download button and download the animation clip. Okay, I've downloaded
the idle animation. Let's drag the animation inside the three D
characters folder. Now click on my idle
animation clip. Go to rig here, animation
type slcumanoid, and click on Apply
the animation here. Check on the loop time, okay? And for root
transform position y. Again, change this to feet
and click on apply here. Click on the animator controller that we created last time. And thus drag the,
my ideal animation here inside the
animator controller. Right click on my
ideal animation and set this as
layer default state. All right, let's
go to the game tab here and let's see how
the animation looks. Okay, It looks fine. Perfect. Inside the
animator controller. This is the entry point. This is the idle animation. We need to create the
transitions here. Right click here on
the idle animation. And make transition
to the mutant walking right click here on the
mutant walking animation. And make transition to
the idle animation. Okay, Click on the arrow here
and select has exit time. Click here on this arrow
and check has exit time. Let's create a bool
parameter here. Okay? And let's name the
parameter as can walk. Let's again select
on the arrow here. And let's add the parameter. Let's add a condition here. Suppose if can walk
value is true mutant, or the character
will start walking. And if the can walk is false, then the idle animation
will be played here. Let's start with declaring a
public float variable here. Public float speed. That will be the speed
of the character. Let's keep it to 2.0 F animator tanning, public float gravity. That's the gravity
for the character. Let's keep it to
nine, public float vertical speed equals to zero. Okay, also we are going to use a Character
controller here. Character controller is
basically used to move the character in Unity Character
Controller controller. And then inside the start
function controller equals to get component Character controller. Okay? And then equals
to get component. Animator. We have not applied character controller
to our character yet. Okay, once we write the script, we are going to apply
character controller to our character. All right, let's declare a function here to
move the character. Let's name the function as move. Okay, so florizontal equals to put, get axis horizontal. And float vertical equals to input get access vertical. Let's write if condition to check if the
controller is grounded. There is a property in
character controller which checks if the character
is grounded or not. Let's apply if
condition controller do is grounded, vertical speed equals to zero L vertical speed minus equals to gravity
into time delta time. After the L condition, we are again going to
declare a vector three, gravity move equals to n vector 30, vertical speed and zero. Then there is one
more vector three to actually move the player
vector three equals to transform forward into vertical plus transform right into horizontal. We're going to use the
controller now to basically move the player controller move, which is the function inside the controller, inside
character controller. In the function, we need
to pass the parameters, which is your player speed into delta t into plus gravity, move into time delta time. Gravity move into
time delta time. Lastly, any set bull can walk vertical n equals to zero or horizontal n equals to zero. Let's call this smooth function, insidety update function Here. Let's save the script. Okay, before running the scene, we need to apply the character controller
to our character. Click on Add Component, Select Character
Controller here. Okay, so we have applied character controller
to the character. Now we need to adjust
the center for the character controller
on the y axis, basically. Okay, let's bring
it up here also, let's change the height. Increase the height a bit. Let's add a script here
which is character walk to the character before
running the scene. Let's get the camera here inside the my character so that the camera will follow
the player basically. Let's run the scene and
let's see how it looks. Yeah, that's fine.
Okay, looking good. That's it guys. In
the next session, we are going to apply rotation to the camera and
to the character as well. If we want to move backward, then we can just rotate
the using mouse here. And also the player will be rotated along with
the camera as well. That's it guys. Thank
you for the session. I will see you in
the next session. Thank you so much guys.
70. Apply rotation to the Camera & make it follow the 3D character: Hi friends, My
name is Rohan Sue. In the last session we applied animation to this
three D character. In this session we are going to apply rotation to the camera. Basically, we are going
to add a piece of code in the script
character walk, which we applied to this
character in the last session. Let's go and write a piece of code inside character
walk script. Here we are in the script. Let's declare some
variables again. Now to rotate the camera. Basically public
transform my cam, public lot mouse sensitivity. We are going to rotate
the camera using a mouse. Here, this variable is for the sensitivity of the
mouse equals to two. Public float up limit equals to -50 And public float down limit equals to 50 F. Okay, so we have declared
four variables here. Let's write a function
here to rotate the camera we rotate. That's the name of the
function inside the function. Float horizontal equals to input dot get axis, mouse x float vertical equals to input do get axis, mouse Y transform Rotate. Basically to rotate the
character zero on the x axis, horizontal into
mouse sensitivity on the y axis, and again zero on the z axis. My rotate minus vertical into mouse sensitivity and 0.0 on the z axis. Now let's get the
current rotation for the camera
using vector three. Vector three current
rotation equals to M local ural angles. Local Euler angles Is
basically used to set the rotation of a game object relative to its parent
coordinate system. All right, if rotation x greater than 180, current rotation x
minus equals to 360. Now next current
rotation x equals to lamp matlam function in Unity Basically
clamps the value, any floating or any integer
value between a given range, between a minimum
and maximum range. All right, the clam function
takes three parameters here. First is the variable
which needs to be clam. Second is the minimum value. And the third parameter is
the maximum value here. All right, we need to
clamp current rotation x, up limit and down limit. Okay? Now, lastly, let's set the local rotation
for the camera. My local rotation equals to quaternion dot Euler. Inside the Euler, we need
to pass current rotation. All right, let's declare this rotate function inside
the update function now. Okay, so rotate. Let's save the script now. And let's go to the
Unity editor now. All right, click on
my character here. And for the character
walk script, okay, we can see a property
here which is my, it's showing none
transform here. So we need to just drag and drop main camera inside this perfect. So we can see the
camera rotating here. What if we want to
move backwards here? We can just rotate the
camera and walk back again. All right. All right, perfect. Looks great. Oh, okay, that's perfect. All right guys,
thank you so much. I will see you in
the next session. Thank you so much, guys.
71. Design a level for Knock the Cans 3D game: Hi friends. My
name is Rohan Sev. In this session, we
are going to create a game called Knock the Cans. The purpose of this game, basically, will be to
knock the cans off. So there will be five cans. All right, and we're going to knock these cans using a ball. Let's start the process
of creating a game. Let's create Plane here
first for the game. Go to Three D and
click on Plane here. Reset the plane. 2000. Get the camera on the z axis to -5.435 0.43 Okay, that's fine. Go to Three D object and
click on plane here. Okay, let's bring it to zero. Let's keep it to 04.524 0.06 rotation on x
axis will be 270. All right, that's it. Let's
create a ball holder here. Basically, a ball holder
is going to be a cube. Okay, I'm going
to create a cube. You can use any kind
of assets you want to. You can use tables. You can use chairs, whatever
you want to. I'm going to create a cube
here as a ball holder. All right, so let's
create a cube. Let's scale the cube
on the x axis to one. On the y axis, keep
it to 0.2 and on the z axis keep it to 0.3 Okay? Position the cube on
the x axis to 00.51 -4.68 Let's create another here can hold, and this is your ball holder. Okay, let's go to can holder. Again, position
the can holder on the x axis to zero here, 0.5 n on the z axis to -1.8 I have downloaded
some textures here. Let's just drag and drop the texture for the
ball holder here. All right, on this our ball will be placed basically
in the center. Okay, let's apply the texture
for the can holder here. Let's apply textures
for the ground here. Plane one, plane two here. Now let's create cans. How do we create cans? We're going to
create a cylinder, basically, for the cans. All right, let's create
your first can here. So go to Game Object, go to Three D, click
on cylinder here. Let's go to Scene more
and scale the can. 20.30 0.30 0.3 Let's place the can here. I think it's too
big. Let's scale it down to 0.2 probably. Yeah, 0.2 and 0.2 Okay, looks better down. Okay, let's place it here. That's the first can. Our can has got a
capsule collider here. Let's remove a capsule
collider for the can. And let's apply a maze collider. Okay? And click on convex here. Let's add a rigid
body to the can. Now let's go to the
can holder here. And let's apply a rigid
body to can holder as well. Okay, let's increase the
mask to probably 500. Select the cylinder game
object here or your first can and press on control D to replicate the
can basically. Okay, let's just place
the cans here properly. Okay, I've created all
then Let's give it a little darker look for
the main camera here. I don't want a sky box
select solid color. Let's apply a black color to it. For the directional light. I don't want a
directional light here. Let's make it dark. And let's add a
spot light to it. Okay, let's bring it here. Let's adjust the spot light. Let's add one more
spot light to it. Yeah, that looks better. Let's reduce the range
a little bit till it starts looking good here. That looks better. All right, let's
create a ball here, which will be placed on
the ball holder here. We have to create a
prefabire basically, which will be spawned or instantiated when we click
on the spawn button, which we are going
to create later. All right, for the ball, let's create a game object here. Go to Game Object and
click on Radio object, and click on Speer here. All right, scale the ball
to 0.15 on the x axis, 0.15 on the y axis, and 0.15 on the z axis. On the x axis position, the ball to zero on the
y axis position to ball 20.691 on the z axis position to ball two -4.695 All right, let's apply a texture
to the ball now. Okay, perfect. Now let's create
a button here on the extreme left
to spawn the ball, because this ball will only be spawned when you click on
the spawn button here. Right click here, game object Y, and click on button here. Okay, left bottom, 55.5 on the y axis
to 26.60 is fine. Keep the width of the
button to 84.5 All right, let's change the color for the button here that
matches the background. Okay, let's change the
text color for the button. Okay. And change
the text to spawn. All right, that's it. We
have created a level here. In the next session,
we're going to create a script to
shoot the ball, to drag and shoot
the ball basically, and to knock the cans down. Also, we're going to
create a script to spawn the ball once we throw
the ball on the can. That's it guys. Thank
you for the session. Thank you so much. I will see you in the next session, guys.
72. Applying Logic to knock the cans down - Part 1: Friends, My name is Rohan Sev. In the last session we
created a level for the game. All right, in this
session we are going to apply a script to the ball so
that we can throw the ball. Shoot the ball on the cans here. But before doing so, let's go to the Sphere game object
here, which is our ball. And let's apply a
rigid body to it. Click on Add Component here
and select Rigid Body here. Let's go and write
a piece of code. Let's create a script
here so that we can attach that script to
the Sphere game object. And then we can throw
the ball on the cans. All right, let's start
writing a piece of code here. Before doing so, we need to
declare a few variables here. Private vector three, mouse press down position, then private vector three, mouse release position, then the rigid body to get the rigid body applied to the sphere game
object, rigid body RB. Then we have private
bull variable to check if we have
thrown the ball or not. To vector three, throw destination y one and y two. Okay, we don't need an
update function here, so let's remove the
update function inside the start function, let's call a rigid body, R B equals to get
component rigid body. So here we are going to use two functions inside unit
one is your mouse down. Mouse down is used
to detect when we have clicked
the mouse button. And the second function
is the mouse up function. It is triggered when you actually release
the mouse button. All right, so let's create
void on mouse function. Mouse press down
position because this is where you are clicking
on the ball to throw it. All right, mouse press
down position equals to input dot mouse position, the ray one equals two, camera main screen point to ray. Mouse press down position. Camera screen point to function basically returns a ray going from camera through
a screen point. After this, we're going to
declare one up function. This is triggered when
you release the mouse. All right, mouse
release position equals to input mouse position. Okay, this is when you release the mouse to shoot
the ball again. Ray two equals to camera, main screen, point to mouse release position. We're going to
create a cast, hit, hit result. What is cast Cast in Unity
is like a laser beam. Basically, it's like
a ray basically, which starts from
its origin point, moves ahead in its
specified direction and goes to its maximum
distance specified. All right, cast will return true if it gets hit
with any object falls. Now this object needs
to have a collider, then physics two and then out throw destination equals to F result point. Let's create another function to actually shoot the ball in
this particular direction. Now we have a throw destination. Okay, so let's create a
function here to actually shoot the ball void cath, then return equals to true R B for n vector three. Throw destination
x on the x axis, then throw destination
on the y axis, and throw destination again on the z axis into 160 is fine. Let's declare this cast function here inside one up function. Okay, so when we release the mouse recast shoot function
will be triggered here. Click on the spear game object. Here we have already
applied rigid body. Let's apply the script now. Drag and throw. Okay, let's run the
scene and let's see if we can shoot the
ball on the cans now. Yes. All right guys,
thank you so much. I will see you in
the next session. Thank you so much guys.
73. Applying Logic to knock the cans down - Part 2: My friends, my name
is Rohan Vase. In this session, we are
going to create two scripts. One is the managers script, which is going to
manage the entire game. And the other is the
script where we are going to detect if the can has
been knocked down or not. But before doing so, we are
going to create a tag and attach this tag to the
plain game object here. Okay, so go to plain object
and select tag here, and click on a tag. Then new tag, name my crowd. Just save it. All right, so we have our tag here
which is my ground. Again. Click on
plain game object, go to tag and select
my ground here. All right, Okay. Inside the manager script, let's declare two variables. Public in number of cans equals to zero. Public in chance
count equals to zero. Now let's create an empty
game Object Manager. And let's attach
the Managers script to the empty game object. All right, game object, create empty name the object as Manager go to add component
here and manager script. Let's start with declaring the variable bole
j equals to false. Then we have inside
the start function, we need to find the
game object to which this manager script is attached
to. How do we do that? M equals to find object type manager
inside the update. Let's write if condition to check if the can has been
knocked down or not. We are going to check for
the position of the can. Basically, let's
write F condition. If game object transform do up y lesser than 0.5 check equals to equals to false, number of knock equals to m, number of cans knocked plus
one and check equals to true. Now to detect the
collision with the floor, let's write on collision
enter function here, void on collision enter
collision call call game object tag equals
to equals to my ground and check falls number of
cans knocked equals to m, number of cans knocked plus
one checked equals to true. Click on cylinder one here, he can down to view the
number of cans knockdown. Click on the manager game object here and let's run the
scene. Let's throw the ball. Okay, we have one
can knock down. Okay, let's play the game again. Okay, we have knocked two cans. Now it's working perfect. But we can see here the chance
count is not increasing. Let's also increase the
number of chance count. Here, let's declare a. Okay? And again, M
equals to find object of type manager inside the
car shoot function M, chance count equals to M
chance count plus one. Okay, so four cans, number of cans knocked is
four and chance count is one. It's working. Perfect.
Thank you guys. Thank you for the session. In the next session,
we are going to write a script to spawn the ball. Thank you guys. I'll see you in the next session.
Thank you so much.
74. Prefab creation & Instantiation in Knock the Cans game: Hi friends, my name
is Rohan Suede. In this session, we
are going to spawn the ball using this spawn
button Here altogether, the player is going to get five chances to spawn the ball. All right, but to
spawn the ball, we need to create a
prefab out of the ball. A prefab is basically a
simple template which can be used to create instances of
that particular game object. All right, but before creating
a prefab of the ball, let's tag the ball first. Okay, go to the spear
game object here and click on Tag and
add new tag here. Name the tag as my
ball and save it. Okay, Again, click on the
sphere game object here. Go to tag and select
my ball here. All right, and the tag, my ball now is added to
the sphere game object. Okay, after doing
that, create a folder called prefabs inside
the asset folder. And just drag and drop your
sphere game object inside the prefabs folder and
the prefab is created. Since we have created
a prefab here, we will disable the
sphere game object. And the Sphere game object
by default won't be visible inside the scene unless we click on the spawn button here. Okay, so let's go and
write a piece of code to spawn the Sphere game object
or the ball in the game. All right, so I have already created a script here
called ball spawn. Let's declare a few
variables here. Manager M, game object, ball inside the start function. Again, we need to find the
object of type manager, find object of type manager. We don't need an
update function here. Let's just remove
the update function instead of update function. Let's create a function,
a custom function, public void spawn ball. Let's write an if condition. If game object find
object with tag, my ball equals to null. This is to check if the ball is already
been spawned or not. Chance count less than five, We are giving the
player only five chances to knock
all the cans off. Okay, the chance count should be lesser than five if we
want to spawn the ball. To spawn the ball, we
need to use instantiate, which is a function in Unity. Let's put a ball and the position at which we
want to spawn the object. Zero on the x axis, 0.691 on the y axis, -4.695 on the z axis, and for the rotation
squatanion identity. Let's write an condition
also print ball exists. Now go to drag and throw script. Once we shoot the
ball here and once the chance count is increased by one here or
incremented by one here. Let's destroy the
game object here, Destroy game object
after 3 seconds. Let's create an empty
game object here, and name the game
object as spawn. Okay, create empty. Let's name this object
as spawn object. Okay, and let's attach the script ball spawn
to this object. Ball spawn. Okay, now we can see none game
object here for the ball. So let's just drag and
drop the prefab here. Inside this, open
the canvas here, go to the button, this
is the spawn button. Basically click on
this Plus here, just drag the spawn object here. Go to ball spawn and
spawn ball function. And let's run the
scene and let's see if we are able to
spawn the ball or not. Okay, let's strike clicking
on the spawn button here. Yes, we are able
to spawn the ball. Okay, ball already exists. Okay, let's go to the manager here and let's look
at the chance count. So yes, it's two. Let's spawn the ball again. Okay. Three, okay. Three cans knocked and
four chances gone. Are we able to
spawn the ball now? Oh, here it shows
ball already exists. Chance count is five year, and in fact, our game is over. So in the next session, we
are going to create a pop up. Okay, wherein we are
going to display the game is over once the
chance count is five. All right guys,
Thank you so much. I will see you in
the next session. Thank you so much, guys.
75. Create a win or lose system in the game & final words: Friends, My name is Ron Masurev. In this session, we
are going to create a pop up to know if the player has won the game or if the
player has lost the game. Right, click on the canvas here, go to Y and click on Panel. Let's name it as
Wind Panel here. And keep it to stretch. Stretch. Let's adjust the panel. Now let's change the
color for the panel here. Now inside the panel,
let's add text, right? Click on the panel here, go to Y and go to text Mesio. Let's reduce the size to 16. Yes, that's fine. Let's change the color
for the text here. Let's keep it to red color. Let's change again the
color for the button here. Let's keep it yellowish button. Extend the button here. Let's change this
to replay again. Change the color for the
font here or the text. Let's keep it to black. Uncheck the wind panel now, because we don't want to show it at the start of the game, we just want to show it if the
player wins the game here. Let's just check this
on the text here. Instead of won the game, just change it to Lost the game. Keep the text for
the button as it is. Okay, we have created two panel, one is the wind panel. Another is the loose panel here. Uncheck the loose panel here. Now let's go to the
managers script. And let's write a piece
of code to actually display these panels on
the basis of the results, whether the player
has lost the game or whether the player
has won the game. Let's declare a
bull variable here. Bol, decision made
equals to false. Public game wind panel, public game object, loose panel. Now let's create a
coutine function here. Tine is basically a special
function Unity used to stop any kind of execution until some
condition is met. Again, it continues from
where it has left off. Enumerator load, wind
panel yield return, new weight for seconds, one wind panel set active through then decision
made equals to true. I enumerator load
loose panel yield return new weight for seconds, 3.5 loose panel set active, true decision made
equals to true. Inside the update function, if number of cans knocked
equals to equals to five, decision made
equals to equals to falls and chance count
lesser than equal to five. To run the cortine function, we need to use start curtin. Inside this we can pass our function which
is load wind panel. If number of cans knock lesser than five and decision
made equals to equals to, falls chance count equals
to equals to five. Then start curtin load
loose panel. That's it. Now go to the manager
game object here. Just drag and drop
wind panel here to wind panel and loose panel
here for the loose panel. All right, so this
is a replay script. We don't need start and
update functions here. Let's create a function
here to restart a game. Public void Restart
Scene Manager, Load scene, knock can level one. That's the name of our scene. Basically it's knock
cans level one. But we can see the error here. Okay, Unity Engine management, we need to import Unity Engine. Do Seen Management. If we want to use scene
manager in the scene, extend the wind panel here and go to the button
inside the wind panel. Click on Ad Component
and Silplay, click on the here, drag the button here to
replay Silic Restart here. Let's run the scene now and let's see how the
game looks now. Okay, you have won
the game, great. So let's click on the
replay button here. Okay, you have lost the game. Let's click on the
replay button again, and we can again start
playing the game here. So that's it guys,
that's the end of the gaming with
Unity part one. Here in this series, we started with Unity
installation and basics of C Sharp such
as variable declaration, control, flow, statements,
loops and collections. Furthermore, we went
on to creating UI, Unity events and delegates and learned about
Unity input system. We also learned about
physics engine immunity, which included rigid
body and collisions. Proceeding further,
we learned about Tod and Three D
animations in Unity. And lastly, we developed a game called Knock
the Cans Down, but this is not the
end of the tutorial. Soon I'll be coming up with more complex topics on gaming. Wearing the End, we
will be developing a RPG shooter based
game in Unity. That's it guys, Thank you for all the support and thank
you for listening to me. Thank you so much, guys. See you soon again.
Thank you so much.