2 Sprites and Animations
7K views
Oct 30, 2023
Sprites and animations in Unity3D Background music - Song: Ehrling - You And Me (Vlog No Copyright Music) Music provided by Vlog No Copyright Music. Video Link: https://youtu.be/8HJSl7AiJNg
View Video Transcript
0:00
Hello guys this is Vivek Sharma and welcome to yet another Unity tutorial on C Sharp Corner.com
0:05
In the previous video we learned how to download and install Unity and also got an overview of it
0:11
In this video we will learn about sprites, sprite animations, type of sprites and also
0:17
we'll learn about collision and physics in Unity. So without wasting any further time let's get started
0:23
So what are sprites? Sprites are just 2D graphical objects
0:32
They are essentially basic textures, but they use special techniques to increase the efficiency
0:38
and the convenience of use. We can use sprites in two ways, either by using single images or by using sprite sheets
0:46
We will learn about them in detail in just a minute. over here, I have a png image file with a transparent background and a bird on it
0:54
This is another image of the same bird but in another pose
0:58
So I can say over here I have two sprites of the same bird So what I gonna do now is create a sprite animation by using these two images So to do that first of all I will create a new folder will call it sprites and then
1:11
we'll drag these two bird images inside that sprites folder. Now by selecting these two sprites at the same time and dragging them into the hierarchy
1:20
panel I get some pop-up saying create a new animation. I will name this animation and then I will hit play
1:28
Okay, so we can see that our bird is flying now. So what actually is happening over here is, those two images are getting rendered sequentially
1:36
in a continuous manner. Now let's talk about sprite sheets. A sprite sheet is a texture containing small images with a transparent background
1:45
Over here I have a sprite sheet in which I have a dinosaur in various poses
1:50
So now what I am gonna do is drag this sprite sheet into the sprites folder and then click
1:54
on it. Now I have to make sure that the texture type is set to Sprite 2D UI
2:01
Second, we have to change the sprite mode from single to multiple and then click on Sprite editor
2:07
We will hit apply over here then slice slice and then apply again And now if we click on this small triangle we can see our sprite sheet has got divided into different sprites Now similar to
2:20
what we did last time we can select any of the sprites we want to animate, drag them into the
2:25
hierarchy panel, create a new animation and then hit play and here we can see that our sprites are
2:31
getting animated. So that's all about the sprites and sprite animation inside the unity. So right now
2:37
Otherwise you can see our dinosaur is just getting animated and not doing anything much
2:42
This is because for Unity, this is just a sprite and a sprite animation right now
2:46
It do not have any colliders, an outside body or any physics interactions
2:51
So to achieve that, what we will do is we will click on the Dino Player in the Hierarchy
2:55
Panel, we will go to the Inspector Panel and we will click on Add Component to add new
3:01
properties and components to our dinosaur. First of all, I'm gonna search for box collider
3:08
Over here we have two box colliders, box collider and box collider 2D
3:12
Right now we are creating a 2D game, that why we will be using box collider 2D So let click on this And now as you can see there is a green boundary surrounding our dinosaur So that means this is the border or the boundary or the body of our dinosaur now So let hit play again but now also we
3:29
don't see any big changes. This is because our dinosaur do not have any mass, any
3:33
gravity, any velocity, any friction or any other physics interaction. To add that
3:38
we will again go back to the inspector panel, click on add component and this
3:43
time we are going to add rigidbody 2D. So rigidbody 2D is the component
3:48
responsible for adding physics to any of the game objects like velocity, gravity
3:53
friction, force, anything like that. So now if we will hit play we will see that
3:59
our dinosaur starts falling and this is what we wanted to achieve. Great! So this
4:04
is it for this video. In the next video we will see how we can move our dinosaur
4:09
in the desired way. Till then goodbye have fun and don't forget to follow and
4:13
subscribe because the best is here to come
#Action & Platform Games
#Action Figures
#Computer Education
#Development Tools
#Educational Toys
#Video Game Development