Add Animation – Unity3D
Animations are used for animating any movement or stand position of an object. Some game objects in asset store have their own animation as you know but you can add animation even for a single cube. You can change rotation or position of a 3D object to animate.
2D animation is created by 2 frames at least. For example, you can create a walking animation with 2-3 frames. In this post, I will show you how to create a simple Pac-Man animation.
You can draw yourself or download a sprite sheet to get animation images. Every image should be placed different frame. Sprite sheet must be .PNG format and transperant.
You can download this sprite for this tutorial. Pac-Man moves 4 direction. So, there are 2 ways to create move animation for Pac-Man: 4 separate animations for each movement or 1 animation for all movement and rotate with code for each direction.
Open a 2D project in Unity and import the sprite sheet above. Click on sprite sheet and edit sprite setting. Multiple for Sprite Mode means we have more than 1 image in sprite sheet. Pixels Per Unit provides an exacy fit on scene. Usually, you should enter the size of your single-major image. It is 32 for our sprite sheet(we will use the big ones). Click Sprite Editor.
Click slice and slice the sprite sheet into the small images. Each image has different name and different position. You can edit these properties. When you apply changes, you see 12 different and independent sprites under the sprite sheet. I will use 3, 8, 11 but it may be different in yours. Rename your sprites to avoid any mistake.
Select 3 big sprites and drag them into the scene. A save window will be appear. Give a name to your animation and save it. Press play and test it. You get a Pac-Man Animation! You can change animation speed in Animation window under Window menu. The number across Sample gives speed of animation. You can decrease or increase it. Create a C# script and write some keyboard controllers see that it is animated while moving but it faced only +X direction. Use transform.localScale to reverse object. Also, you can rotate it when it moves upward and downward with Quaternion.eulerAngles. You can get more help from Mario Tutorial about animations.
©Coffee Break Codes – Add 2D Animation – Unity3D