Flipping a sprite horizontally
Perhaps the simplest 2D animation is a simple flip, from facing left to facing right, or facing up to facing down, and so on. In this recipe we'll add a cute bug sprite to the scene, and write a short script to flip its horizontal direction when the Left and Right arrow keys are pressed.
Getting ready
For this recipe, we have prepared the image you need in a folder named Sprites
in folder 1362_03_01
.
How to do it...
To flip an object horizontally with arrow key presses, follow these steps:
- Create a new Unity 2D project.
- Import the provided image
EnemyBug.png
. - Drag an instance of the red Enemy Bug image from the Project | ...
Get Unity 5.x Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.